This class represents the angelscript scripting interface.
More...
#include <ScriptEngine.h>
|
| ScriptEngine () |
|
| ~ScriptEngine () |
|
ScriptUnitId_t | loadScript (Ogre::String scriptname, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="") |
| Loads a script. More...
|
|
void | unloadScript (ScriptUnitId_t unique_id) |
| Unloads a script. More...
|
|
void | framestep (Ogre::Real dt) |
| Calls the script's framestep function to be able to use timed things inside the script. More...
|
|
void | activateLogging () |
|
void | triggerEvent (scriptEvents eventnum, int arg1=0, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="") |
| triggers an event; Not to be used by the end-user. More...
|
|
void | setEventsEnabled (bool val) |
|
int | executeString (Ogre::String command) |
| executes a string (useful for the console) More...
|
|
void | queueStringForExecution (const Ogre::String command) |
| Queues a string for execution. More...
|
|
int | addFunction (const Ogre::String &arg) |
| Adds a global function to the script. More...
|
|
int | functionExists (const Ogre::String &arg) |
| Checks if a global function exists. More...
|
|
int | deleteFunction (const Ogre::String &arg) |
| Deletes a global function from the script. More...
|
|
int | addVariable (const Ogre::String &arg) |
| Adds a global variable to the script. More...
|
|
int | deleteVariable (const Ogre::String &arg) |
| Deletes a global variable from the script. More...
|
|
int | fireEvent (std::string instanceName, float intensity) |
|
void | envokeCallback (int functionId, eventsource_t *source, NodeNum_t nodenum=NODENUM_INVALID, int type=0) |
|
void | forwardExceptionAsScriptEvent (const std::string &from) |
| Forwards useful info from C++ try{}catch{} exceptions to script in the form of game event. More...
|
|
AngelScript::asIScriptEngine * | getEngine () |
|
void | messageLogged (const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage) |
|
bool | scriptUnitExists (ScriptUnitId_t unique_id) |
|
ScriptUnit & | getScriptUnit (ScriptUnitId_t unique_id) |
|
ScriptUnitMap const & | getScriptUnits () const |
|
|
|
void | init () |
| This function initialzies the engine and registeres all types. More...
|
|
Ogre::String | composeModuleName (Ogre::String const &scriptName, ScriptCategory origin, ScriptUnitId_t id) |
| Packs name + important info to one string, for logging and reporting purposes. More...
|
|
int | setupScriptUnit (int unit_id) |
| Helper for loadScript() , does the actual building without worry about unit management. More...
|
|
bool | prepareContextAndHandleErrors (ScriptUnitId_t nid, int asFunctionID) |
| Helper for executing any script function/snippet; does asIScriptContext::Prepare() and reports any error. More...
|
|
int | executeContextAndHandleErrors (ScriptUnitId_t nid) |
| Helper for executing any script function/snippet; registers Line/Exception callbacks (on demand) and set currently executed NID; The asIScriptContext::Prepare() and setting args must be already done. More...
|
|
|
void | msgCallback (const AngelScript::asSMessageInfo *msg) |
| Optional (but very recommended!) callback providing diagnostic info when things fail to start (most notably script errors). More...
|
|
void | lineCallback (AngelScript::asIScriptContext *ctx) |
| Optional callback which receives diagnostic info for every executed statement. More...
|
|
void | exceptionCallback (AngelScript::asIScriptContext *ctx) |
| Optional callback invoked when the script critically fails, allowing debugging. More...
|
|
This class represents the angelscript scripting interface.
It can load and execute scripts.
- Authors
- Thomas Fischer (thomas{AT}rigsofrods{DOT}com)
Definition at line 107 of file ScriptEngine.h.
◆ ScriptEngine()
ScriptEngine::ScriptEngine |
( |
| ) |
|
◆ ~ScriptEngine()
ScriptEngine::~ScriptEngine |
( |
| ) |
|
◆ activateLogging()
void ScriptEngine::activateLogging |
( |
| ) |
|
◆ addFunction()
int ScriptEngine::addFunction |
( |
const Ogre::String & |
arg | ) |
|
Adds a global function to the script.
- Parameters
-
arg | A declaration for the function. |
Definition at line 484 of file ScriptEngine.cpp.
◆ addVariable()
int ScriptEngine::addVariable |
( |
const Ogre::String & |
arg | ) |
|
Adds a global variable to the script.
- Parameters
-
arg | A declaration for the variable. |
Definition at line 619 of file ScriptEngine.cpp.
◆ composeModuleName()
Packs name + important info to one string, for logging and reporting purposes.
Definition at line 712 of file ScriptEngine.cpp.
◆ deleteFunction()
int ScriptEngine::deleteFunction |
( |
const Ogre::String & |
arg | ) |
|
Deletes a global function from the script.
- Parameters
-
arg | A declaration for the function. |
Definition at line 565 of file ScriptEngine.cpp.
◆ deleteVariable()
int ScriptEngine::deleteVariable |
( |
const Ogre::String & |
arg | ) |
|
Deletes a global variable from the script.
- Parameters
-
arg | A declaration for the variable. |
Definition at line 639 of file ScriptEngine.cpp.
◆ envokeCallback()
◆ exceptionCallback()
void ScriptEngine::exceptionCallback |
( |
AngelScript::asIScriptContext * |
ctx | ) |
|
|
protected |
◆ executeContextAndHandleErrors()
Helper for executing any script function/snippet; registers Line/Exception callbacks (on demand) and set currently executed NID; The asIScriptContext::Prepare()
and setting args must be already done.
- Returns
- 0 on success, anything else on error.
Definition at line 264 of file ScriptEngine.cpp.
◆ executeString()
int ScriptEngine::executeString |
( |
Ogre::String |
command | ) |
|
executes a string (useful for the console)
- Parameters
-
Definition at line 466 of file ScriptEngine.cpp.
◆ fireEvent()
int ScriptEngine::fireEvent |
( |
std::string |
instanceName, |
|
|
float |
intensity |
|
) |
| |
◆ forwardExceptionAsScriptEvent()
void ScriptEngine::forwardExceptionAsScriptEvent |
( |
const std::string & |
from | ) |
|
Forwards useful info from C++ try{}catch{}
exceptions to script in the form of game event.
AngelScript doesn't have exceptions in this sense (in AS jargon, 'Exception' means basically 'panic' as in Lua/Rust...) and most exceptions this game encounters (Ogre::Exception
) are trivially recoverable, so it doesn't make sense to panic AngelScript when they happen.
Definition at line 233 of file ScriptEngine.cpp.
◆ framestep()
void ScriptEngine::framestep |
( |
Ogre::Real |
dt | ) |
|
Calls the script's framestep function to be able to use timed things inside the script.
- Parameters
-
dt | time passed since the last call to this function in seconds |
Definition at line 371 of file ScriptEngine.cpp.
◆ functionExists()
int ScriptEngine::functionExists |
( |
const Ogre::String & |
arg | ) |
|
Checks if a global function exists.
- Parameters
-
arg | A declaration for the function. |
Definition at line 540 of file ScriptEngine.cpp.
◆ getEngine()
AngelScript::asIScriptEngine* RoR::ScriptEngine::getEngine |
( |
| ) |
|
|
inline |
◆ getScriptUnit()
◆ getScriptUnits()
◆ init()
void ScriptEngine::init |
( |
| ) |
|
|
protected |
This function initialzies the engine and registeres all types.
Definition at line 108 of file ScriptEngine.cpp.
◆ lineCallback()
void ScriptEngine::lineCallback |
( |
AngelScript::asIScriptContext * |
ctx | ) |
|
|
protected |
◆ loadScript()
Loads a script.
- Parameters
-
scriptname | filename to load; if buffer is supplied, this is only a display name. |
category | How to treat the script? |
associatedActor | Only for category ACTOR |
buffer | String with full script body; if empty, a file will be loaded as usual. |
- Returns
- Unique ID of the script unit (because one script file can be loaded multiple times).
Definition at line 717 of file ScriptEngine.cpp.
◆ messageLogged()
void ScriptEngine::messageLogged |
( |
const Ogre::String & |
message, |
|
|
Ogre::LogMessageLevel |
lml, |
|
|
bool |
maskDebug, |
|
|
const Ogre::String & |
logName, |
|
|
bool & |
skipThisMessage |
|
) |
| |
◆ msgCallback()
void ScriptEngine::msgCallback |
( |
const AngelScript::asSMessageInfo * |
msg | ) |
|
|
protected |
Optional (but very recommended!) callback providing diagnostic info when things fail to start (most notably script errors).
Definition at line 183 of file ScriptEngine.cpp.
◆ prepareContextAndHandleErrors()
bool ScriptEngine::prepareContextAndHandleErrors |
( |
ScriptUnitId_t |
nid, |
|
|
int |
asFunctionID |
|
) |
| |
|
protected |
Helper for executing any script function/snippet; does asIScriptContext::Prepare()
and reports any error.
- Returns
- true on success, false on error.
Definition at line 351 of file ScriptEngine.cpp.
◆ queueStringForExecution()
void ScriptEngine::queueStringForExecution |
( |
const Ogre::String |
command | ) |
|
Queues a string for execution.
Use this when you want to execute a script statement from another thread.
- Parameters
-
command | string to queue for execution |
- See also
- executeString
Definition at line 461 of file ScriptEngine.cpp.
◆ scriptUnitExists()
◆ setEventsEnabled()
void RoR::ScriptEngine::setEventsEnabled |
( |
bool |
val | ) |
|
|
inline |
◆ setupScriptUnit()
int ScriptEngine::setupScriptUnit |
( |
int |
unit_id | ) |
|
|
protected |
Helper for loadScript()
, does the actual building without worry about unit management.
- Returns
- 0 on success, anything else on error.
Definition at line 766 of file ScriptEngine.cpp.
◆ triggerEvent()
void ScriptEngine::triggerEvent |
( |
scriptEvents |
eventnum, |
|
|
int |
arg1 = 0 , |
|
|
int |
arg2ex = 0 , |
|
|
int |
arg3ex = 0 , |
|
|
int |
arg4ex = 0 , |
|
|
std::string |
arg5ex = "" , |
|
|
std::string |
arg6ex = "" , |
|
|
std::string |
arg7ex = "" , |
|
|
std::string |
arg8ex = "" |
|
) |
| |
◆ unloadScript()
◆ GameScript
◆ context
AngelScript::asIScriptContext* RoR::ScriptEngine::context |
|
protected |
context in which all scripting happens
Definition at line 277 of file ScriptEngine.h.
◆ engine
AngelScript::asIScriptEngine* RoR::ScriptEngine::engine |
|
protected |
◆ m_currently_executing_event_trigger
◆ m_currently_executing_script_unit
◆ m_events_enabled
bool RoR::ScriptEngine::m_events_enabled = true |
|
protected |
Hack to enable fast shutdown without cleanup.
Definition at line 284 of file ScriptEngine.h.
◆ m_game_script
◆ m_script_units
◆ m_terrain_script_unit
◆ scriptLog
◆ stringExecutionQueue
The documentation for this class was generated from the following files: