Inheritance diagram for nrEngine::ScriptConnector:
Public Member Functions | |
virtual | ~ScriptConnector () |
Protected Member Functions | |
void | initialize () |
ScriptConnector (const std::string &name) | |
void | OnEvent (const EventChannel &channel, SharedPtr< Event > event) |
virtual void | OnRegisterFunction (const std::string &name, const ScriptFunctor &func)=0 |
virtual void | OnRemoveFunction (const std::string &name)=0 |
In our engine we do provide some default behaviour of how to access registered engine's functions in your scripts. However if you implement a new embedded scripting language you have somehow to bind the calling of engine's provided function within your script. Only the functions which are registered in ScriptEngine are for the public use within the engine.
To connect your scripts with the functions you can ask scripting engine for registered functions and somehow connect them. The other more elegant way is to derive a class from this one. If any instance of this class is created (done automaticaly by the constructors), so the class will act as a event listener and wait for certain scripting engine events. If they occurs it will call virtual functions overwriten by your class which handle this events. In this way you just derive any new class from this one and write a glue code to connect new functions (coming by events) within your scripting language.
Definition at line 47 of file ScriptConnector.h.
nrEngine::ScriptConnector::~ScriptConnector | ( | ) | [virtual] |
Remove the listener and release used memory
Definition at line 39 of file ScriptConnector.cpp.
References nrEngine::EventActor::disconnect().
nrEngine::ScriptConnector::ScriptConnector | ( | const std::string & | name | ) | [protected] |
Protected constructor, so you can only create instancies of this class in derived classes. The constructor will add itself as a listener on scripting evnets.
Definition at line 21 of file ScriptConnector.cpp.
References nrEngine::EventActor::connect().
void nrEngine::ScriptConnector::initialize | ( | ) | [protected] |
Call this function to get noticed about all currently registered functions This function should be called from the constructor of derived class.
Definition at line 27 of file ScriptConnector.cpp.
References nrEngine::ScriptEngine::getFunction(), nrEngine::ScriptEngine::getFunctionCount(), OnRegisterFunction(), and nrEngine::Engine::sScriptEngine().
void nrEngine::ScriptConnector::OnEvent | ( | const EventChannel & | channel, | |
SharedPtr< Event > | event | |||
) | [protected, virtual] |
React on events coming from the scripting engine
Implements nrEngine::EventActor.
Definition at line 45 of file ScriptConnector.cpp.
References OnRegisterFunction(), and OnRemoveFunction().
virtual void nrEngine::ScriptConnector::OnRegisterFunction | ( | const std::string & | name, | |
const ScriptFunctor & | func | |||
) | [protected, pure virtual] |
New function was registered, so handle it
Referenced by initialize(), and OnEvent().
virtual void nrEngine::ScriptConnector::OnRemoveFunction | ( | const std::string & | name | ) | [protected, pure virtual] |
A function was removed from the database
Referenced by OnEvent().