--------------------------- --------------------------- -- Tutorial: Using program options. -- -- Copyright (c) 2006-2008 Capricorn 76 Pty. Ltd. --------------------------- --------------------------- --------------------------- --------------------------- -- PROGRAM STARTS HERE -- All global code (outside of any functions) is first run. -- Then the ScriptENGINE automatically run the State Machine by looking for the OnStateRun_[scriptName]() function. -- If its not found (in this case it is), then the ScriptENGINE will look for the fallback function OnStateRun() --------------------------- --------------------------- function OnStateRun_test1(param) -- Show the console window IApp:showConsoleWindow(); -- Load options from file -- This already defined some options IApp:loadOptions('test.dat'); -- Iterate over all options, and print them to the console print('--- PRINTING OPTIONS ---'); IApp:forEachOption('OnIterateOptions'); -- Set some new options print('--- Adding new options ---'); IApp:setOptionInt('mysection', 'intData', 1234); IApp:setOptionBool('mysection', 'boolData', true); IApp:setOptionFloat('mysection', 'floatData', 987.654); IApp:setOption('mysection', 'stringData', 'abcdefg'); -- Iterate over all options, and print them to the console print('--- PRINTING OPTIONS ---'); IApp:forEachOption('OnIterateOptions'); -- Wait for user input print('Press any key to exit...'); IKey:getch(); end --------------------------- -- Iterate all program options, and add items to the list --------------------------- function OnIterateOptions(section, key, stringValue, userData) local str = string.format('[%s:%s] = %s', section, key, stringValue); print(str); end
Copyright © 2006-23 Sep 2009 Capricorn 76 Pty. Ltd. (created on Wed Sep 23 16:49:11 2009)