| 12 | #include <nrEngine/nrEngine.h> |
| 13 | |
| 14 | using namespace nrEngine; |
| 15 | |
| 16 | |
| 17 | class SomeClass |
| 18 | { |
| 19 | // here we initialize our class |
| 20 | void init(); |
| 21 | |
| 22 | // We want to register this method in the engine |
| 23 | ScriptFunctionDef(someScriptFunction); |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | // Implementation of the registered function |
| 28 | ScriptFunctionDec(SomeClass, someScriptFunction) |
| 29 | { |
| 30 | // The function macro does provide us with a user defined parameters |
| 31 | SomeClass* class = ScriptEngine::parameter_cast<SomeClass* >(param[0]); |
| 32 | |
| 33 | // return if a wrong number of arguments were passed |
| 34 | if (args.size() <= 1){ |
| 35 | return ScriptResult(std::string("someClass.scriptFunc(arg1) : wrong parameter count")); |
| 36 | } |
| 37 | |
| 38 | // do your stuff |
| 39 | .... |
| 40 | |
| 41 | |
| 42 | // return empty result |
| 43 | return ScriptResult(); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | // Register new methods in the engine |
| 48 | void SomeClass::init() |
| 49 | { |
| 50 | // specify user defined parameters, in our case this is the pointer to our class |
| 51 | std::vector<ScriptParam> param; |
| 52 | param.push_back(this); |
| 53 | |
| 54 | // register new functions |
| 55 | Engine::sScriptEngine()->add("someClass.scriptFunc", someScriptFunction, param); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | // Release all registered functions |
| 60 | SomeClass::~SomeClass() |
| 61 | { |
| 62 | Engine::sScriptEngine()->del("someClass.scriptFunc"); |
| 63 | } |
| 64 | |
| 65 | }}} |