MScriptContext

From MaratisWiki
Revision as of 14:52, 7 February 2014 by Dahnielson (Talk | contribs)
Jump to: navigation, search

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