Inheritance diagram for nrEngine::Script:
Public Member Functions | |
Script () | |
Allocate memory and initilize simple script. | |
~Script () | |
Deallocate memory and release used data. | |
Result | loadFromString (const std::string &str) |
Result | fullRun () |
NR_FORCEINLINE void | setRunStepwise (bool b) |
NR_FORCEINLINE bool | isRunStepwise () const |
Data Structures | |
struct | _cmd |
Each command has this type. |
This is a simple script language object. We use this language as engine's default one to load other more powerfull script languages. This languages could be found in plugins.
Also simple scripts can be used to setup some variables or to write config files that will be used to setup the engine's environment. This config files could also contains plugins loading and file system setup. So actually this simple language is enough to write simple applications.
The scripts have very simple syntax:
Example of such a script (I called this timeline scripts):
seq_command param1 // execute seq_command sequantially with param1 as first argument 1.452 | cmd1 par1 // execute the command cmd1 with parameter par1 at the time 1.452s (after starting of the script) 1.693 | run script/script2.tml // execute script script/script2.tml after the time reaches 1.693
Scripts could include subscripts. Subscripts are defined between {} - brackets. The string between this brackets is used as a scipts as if it was used in an explicit file. So the string is parsed as a script and runs also parallel to the parent script. For timed and non-timed commands the same restrictions are used as in non-subscripts. Subscripts could define new subscripts. Because scripts are running as task, we add a task dependency between parent script and subscript. So parent script depends on subscript. This means parent script can only step forward after subscripts has done their steps.
NOTE:
Definition at line 73 of file Script.h.
Result nrEngine::Script::loadFromString | ( | const std::string & | str | ) | [virtual] |
Load simple script language from a string. Load a script from string. The given string should contain the script in the appropriate language, so it can be executed.
str | String containing the script |
Implements nrEngine::IScript.
Definition at line 47 of file Script.cpp.
References nrEngine::IResource::getResourceName(), nrEngine::IScript::mContent, nrEngine::IScript::notifyLoaded(), nrEngine::OK, and nrEngine::ITask::setTaskName().
Result nrEngine::Script::fullRun | ( | ) |
Execute the script completely. So the script will be executed until it finishes. This function will lock the execution of the engine while the script is running.
NOTE: Timed commands used in nrScript would not been executed here. This is because of the time which will not be updated while the script is running. Updating the time, means either to update the clock or the kernel. This is not allowed by tasks, it means tasks can not update them self only kernel can do this.
So if you call execute() so only sequential commands will be executed!
NOTE: Be carefull by using looped scripts. If there is a loop, so the script will also be executed in loop mode, so if you do not stop it somehow your application could not react anymore!!! If the script is looped, so warnign will be printed in a log file!
Definition at line 522 of file Script.cpp.
References nrEngine::ScriptEngine::call(), nrEngine::IResource::getResourceName(), nrEngine::Log::LL_WARNING, nrEngine::Log::LOG_ENGINE, nrEngine::OK, and nrEngine::Engine::sScriptEngine().
NR_FORCEINLINE void nrEngine::Script::setRunStepwise | ( | bool | b | ) |
Set if this script should run stepwise or completely in one cycle. If you run the script stepwise, so each line of the script is executed in one kernel cycle. Also time commands are getting executed as soon, as according time is passed.
If you run the script fully in one cycle, so look to fullRun()
NR_FORCEINLINE bool nrEngine::Script::isRunStepwise | ( | ) | const |