![]() |
Scanframe Modular Application 0.1.0
|
Script interpreter for running a loaded script. More...
#include <ScriptInterpreter.h>


Classes | |
| struct | CodePos |
| Position in the source with line and offset. More... | |
| struct | Instruction |
| Executable instruction as result of interpreting the script. More... | |
Public Member Functions | |
| ScriptInterpreter () | |
| Default constructor. | |
| ~ScriptInterpreter () override | |
| Virtual destructor. | |
| ChangeListener::emitter_type & | getChangeEmitter () |
| Gets the emitter for change events. | |
| std::string | getScriptName () const |
| Gets the name given by the user. Is used for referencing when debugging. | |
| void | setScriptName (const std::string &name) |
| Sets the name given by the user. Is used for referencing when debugging. | |
| void | setOutputStream (std::ostream *os) |
| Sets and enables debugging output stream. | |
| EState | execute (EExecMode exec_mode=emRun) |
| Executes a macro depending on the execution mode. | |
| bool | compile (const char *cmd) |
| Compiles the passed script text and outputs debug info to the stream. | |
| const char * | getStateName (EState exec_state=esCurrent) const |
| Gets the execution state name from the passed state or the current one on state 'esCurrent'. | |
| EState | getState () const |
| std::string | getDebugText () const |
| CodePos | getErrorPos () const |
| ip_type | getInstructionPtr () const |
| ip_type | getErrorInstructionPtr () const |
| Gets the error instruction pointer in case of an error. | |
| std::string | getInstructionText (ip_type ip) const |
| Gets the instruction text at pointer IP. | |
| void | flush () |
| Calls the protected virtual clear function. | |
| bool | callFunction (const std::string &name, bool step_mode) |
| void | callFunction (ip_type ip, bool step_mode) |
| Makes it possible to execute function/gosub. | |
| void | setMaxLoopTime (unsigned long usec) |
| Sets the maximum loop time for this instance. | |
| string_list | getInfoNames () const override |
| Gets names of info structures in lines. | |
| const IdInfo * | getInfo (const std::string &name) const override |
| const TVector< Instruction > & | getInstructions () const |
| Gets the instruction text at pointer IP. | |
| const TVector< VariableInfo * > & | getVariables () const |
| Gets the current variables declared in the script. | |
| string_list | getIdentifiers (EIdentifier id) const override |
| Gets a list of available identifiers. Used for syntax high lighting for example or code completion. | |
| bool | isStepMode () const |
| Get the step mode of the script. | |
Public Member Functions inherited from sf::ScriptEngine | |
| ScriptEngine () | |
| Default constructor. | |
| bool | calculate (const std::string &script, Value &result) |
| Calculates the passed script. | |
| EArithError | getError () const |
| Gets the error value of this instance. | |
| std::string | getErrorReason () const |
| Gets the associated error reason string. | |
| bool | setError (EArithError error_value, const std::string &reason=std::string()) |
| Sets the error value for this instance. | |
| const char * | getErrorText (EArithError error_value=EArithError::aeCurrent) const |
| pos_type | getPos () const |
| Gets the current position. | |
Public Member Functions inherited from sf::ScriptObject | |
| ScriptObject (const char *type_name, ScriptObject *parent=nullptr) | |
| virtual | ~ScriptObject ()=default |
| Virtual destructor which can be overridden to clean up objects. | |
| virtual std::string | getStatusText () |
| Gets the status text of this object for debugging purposes. | |
| int | getRefCount () const |
| Gets the reference count. | |
| operator Value () const | |
| Cast operator to be able to return this instance as a Value. | |
| std::string | getTypeName () const |
| Returns the type name Set at the constructor. | |
| ScriptObject * | getParent () |
| Gets the script object owner. | |
| const ScriptObject * | getParent () const |
| Gets the script object owner. | |
| ScriptObject * | castToObject (const Value &value) |
| Casts a sf::Value::vitCustom typed sf::Value to a ScriptObject typed pointer. | |
Protected Types | |
| enum | EExitCode { ecNormal = 0 , ecError , ecScript , ecApplication } |
| Possible exit codes. More... | |
| enum | EKeyWord { kwNone = 0 , kwIf , kwWhile , kwElse , kwGoto , kwBreak , kwContinue , kwSubroutine , kwReturn , kwExternal , kwExtern } |
| Keywords available for the script. More... | |
Protected Member Functions | |
| bool | getSetValue (const IdInfo *info, Value *value, Value::vector_type *params, bool flag_set) override |
| Overridden from ScriptEngine class. | |
| virtual bool | compileAdditionalStatement (const IdInfo *info, const std::string &source) |
| Compile external supplied keyword. | |
| virtual void | exitFunction (EExitCode exitcode, const Value &value) |
| Function is called at the exit of the script. | |
| virtual void | clear () |
| Clears compiled data can be overridden by derived classes. | |
| virtual void | linkInstruction () |
| Links the labels of the calls in the script. | |
| void | setState (EState exec_state) |
| Sets the execution state. | |
| ip_type | getLabelIp (const std::string &name) |
| Gets the ip from the label name. | |
Protected Member Functions inherited from sf::ScriptEngine | |
| bool | isAlpha (char ch) |
| Determines if the passed character is an alpha one. | |
| bool | getName (std::string &name) |
Protected Member Functions inherited from sf::ScriptObject | |
| void | makeParent (ScriptObject *so) |
| Makes this object the owner of the other object. | |
| void | setParent (ScriptObject *parent) |
| Sets the owner to the pass script object. | |
Protected Attributes | |
| ElapseTimer | _loopTimer |
| Timer to prevent endless loops. | |
| std::ostream * | _outputStream {nullptr} |
| Output stream to write debug information to. | |
Additional Inherited Members | |
Static Public Member Functions inherited from sf::ScriptObject | |
| static const IdInfo * | getInfoUnknown () |
| Returns the static Info structure for unknowns. | |
Script interpreter for running a loaded script.
| typedef TListener<const ScriptInterpreter*> sf::ScriptInterpreter::ChangeListener |
Declare type for listening and at the same time a type for emitting the changes of the script like State and Error and execution pointer.
|
protected |
|
protected |
State of the running script.
| Enumerator | |
|---|---|
| esError | Script went into an error due to compiling or running. |
| esEmpty | Script is empty |
| esCompiled | Script is compiled and ready for initialization. |
| esRunning | Script is running in step mode. (also internally used in run mode) |
| esReady | Script is initialized and ready for running or just finished running. |
| esCurrent | When passed to getStateName() the current state is used. |
| sf::ScriptInterpreter::ScriptInterpreter | ( | ) |
Default constructor.
|
override |
Virtual destructor.
| bool sf::ScriptInterpreter::callFunction | ( | const std::string & | name, |
| bool | step_mode | ||
| ) |
Calls a label/function in the script.
| name | Name of the label. |
| step_mode | When true in step mode |
| void sf::ScriptInterpreter::callFunction | ( | ip_type | ip, |
| bool | step_mode | ||
| ) |
Makes it possible to execute function/gosub.
|
protectedvirtual |
Clears compiled data can be overridden by derived classes.
| bool sf::ScriptInterpreter::compile | ( | const char * | cmd | ) |
Compiles the passed script text and outputs debug info to the stream.
| cmd | Script to compile. |
|
protectedvirtual |
Compile external supplied keyword.
Executes a macro depending on the execution mode.
|
protectedvirtual |
Function is called at the exit of the script.
| exitcode | Exit code provided. |
| value |
| void sf::ScriptInterpreter::flush | ( | ) |
Calls the protected virtual clear function.
|
inline |
Gets the emitter for change events.
| std::string sf::ScriptInterpreter::getDebugText | ( | ) | const |
Gets the debug text.
| ip_type sf::ScriptInterpreter::getErrorInstructionPtr | ( | ) | const |
Gets the error instruction pointer in case of an error.
| CodePos sf::ScriptInterpreter::getErrorPos | ( | ) | const |
Gets the current error position where the compiler stopped.
|
overridevirtual |
Gets a list of available identifiers. Used for syntax high lighting for example or code completion.
Reimplemented from sf::ScriptEngine.
|
overridevirtual |
Overridden from base class to append more information on identifier/keywords.
| name | Name of the identifier or keyword. |
Reimplemented from sf::ScriptEngine.
|
overridevirtual |
Gets names of info structures in lines.
Reimplemented from sf::ScriptEngine.
| ip_type sf::ScriptInterpreter::getInstructionPtr | ( | ) | const |
Gets the current instruction pointer.
|
inline |
Gets the instruction text at pointer IP.
| std::string sf::ScriptInterpreter::getInstructionText | ( | ip_type | ip | ) | const |
Gets the instruction text at pointer IP.
|
protected |
Gets the ip from the label name.
| std::string sf::ScriptInterpreter::getScriptName | ( | ) | const |
Gets the name given by the user. Is used for referencing when debugging.
|
overrideprotectedvirtual |
Overridden from ScriptEngine class.
Reimplemented from sf::ScriptEngine.
| EState sf::ScriptInterpreter::getState | ( | ) | const |
Gets the current execution state.
Gets the execution state name from the passed state or the current one on state 'esCurrent'.
|
inline |
Gets the current variables declared in the script.
| bool sf::ScriptInterpreter::isStepMode | ( | ) | const |
Get the step mode of the script.
|
protectedvirtual |
Links the labels of the calls in the script.
| void sf::ScriptInterpreter::setMaxLoopTime | ( | unsigned long | usec | ) |
Sets the maximum loop time for this instance.
| usec | Microseconds. |
| void sf::ScriptInterpreter::setOutputStream | ( | std::ostream * | os | ) |
Sets and enables debugging output stream.
| void sf::ScriptInterpreter::setScriptName | ( | const std::string & | name | ) |
Sets the name given by the user. Is used for referencing when debugging.
|
protected |
Sets the execution state.
|
protected |
Timer to prevent endless loops.
Must be reset by functions calling external functions.
|
protected |
Output stream to write debug information to.