ulf.schroeter Posted March 5, 2012 Posted March 5, 2012 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.
unclebob Posted March 6, 2012 Posted March 6, 2012 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); }
manguste Posted March 11, 2012 Posted March 11, 2012 Ulf, really good remarks! Renamed, plus examples are added (thanks to Bob :)
Recommended Posts