MScriptContext

(Difference between revisions)
Jump to: navigation, search
(Created page with "MScriptContext is used to manage script functions virtually. Custom functions can be declared during a plugin initialization in c++,<br> you can send values to the script con...")
 
Line 33: Line 33:
 
text = myFunction() -- "Hello World !"
 
text = myFunction() -- "Hello World !"
 
</pre>
 
</pre>
 +
 +
[[Category:C++ API]]

Revision as of 15:52, 7 February 2014

MScriptContext is used to manage script functions virtually.

Custom functions can be declared during a plugin initialization in c++,
you can send values to the script context using pushInt, pushString, etc,
and get arguments from a script call using getInteger, getString, etc

exemple :

#include <MEngine.h>
#include "MyPlugin.h"

int myFunction(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext * script = engine->getScriptContext();
    script->pushString("Hello World !");
    return 1; // return 1 because the function is sending 1 value to the context (use 0 for none, 2 for 2 values...)
}

void StartPlugin(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext* script = engine->getScriptContext();

    script->addFunction("myFunction", myFunction);
}

In lua the function will be used like this :

text = myFunction() -- "Hello World !"
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox