Jump to content

USC interpreter documentation


photo

Recommended Posts

New Unigine script interpreter documentation under https://developer.unigine.com/en/docs/1.0/tools/interpreter/ should

give a hint that script should implement main function as entry point

 

void main()
{
 ......
}

 

Also ist would be helpful to rename the documentation topic from 'interpreter' to 'USC interpreter' to be consistent with other cross-references / forum entries always using USC abreviation.

 

USC interpreter help message should also be changed from 'run script: usc_x86 script.cpp' to 'run script: usc_x86 script.usc for consistency reasons.

 

Finally a short example for proper command-line argument handling would be very helpful for new users.

Link to comment

Hi,

 

Thanks for your help.

 

Here is two samples. I think Nadezhda (manguste) will put them into docs.

 

1. Print all command line args

#!/usr/bin/env usc
/*
*/
void main() {
forloop(int i = 0; getNumArgs()) {
 log.message("Arg [%d]: %s\n",i,getArg(i));
}
}

 

2. Fill some variables and set flags through command line args

#!/usr/bin/env usc
int value1 = 0;
int value2 = 0;
int use_flag = 0;
/*
*/
void main() {
for(int i = 0; i < getNumArgs(); i++) {
 string arg = getArg(i);

 if(arg == "-set_value_1") {
  if(i + 1 >= getNumArgs()) {
continue;
  }
  value1 = int(getArg(++i));
  continue;
 }

 if(arg == "-set_value_2") {
  if(i + 1 >= getNumArgs()) {
continue;
  }
  value2 = int(getArg(++i));
  continue;
 }

 if(arg == "-use_flag") {
  use_flag = 1;
 }
}

log.message("value1: %d\nvalue2: %d\nflag: %d\n",value1,value2,use_flag);
}

Link to comment
×
×
  • Create New...