MScriptContext

From MaratisWiki
Revision as of 22:33, 11 September 2013 by Anael (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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