Changes between Version 2 and Version 3 of ScriptSystem


Ignore:
Timestamp:
09/27/07 21:09:00 (17 years ago)
Author:
art
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ScriptSystem

    v2 v3  
    77A plugin does register itself by the engine and specify which kind of scripts it can handle. It can also register functions and methods with the engine, so that a call of any registered function will lead to call of the implementation of that function. Moreover due to the glue functionality of the engine's scripting system a globaly registered function can be accessed in different scripting languages by its proper name. For this a plugin, providing new scripting language, has to connect functions from the engine's script function database with the language interface it provides. 
    88 
     9To register any new global function in the engine one can use following code sample: 
     10{{{ 
    911 
     12#include <nrEngine/nrEngine.h> 
     13 
     14using namespace nrEngine; 
     15 
     16 
     17class 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 
     28ScriptFunctionDec(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 
     48void 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 
     60SomeClass::~SomeClass() 
     61{ 
     62    Engine::sScriptEngine()->del("someClass.scriptFunc"); 
     63} 
     64 
     65}}} 
    1066 
    1167