Topic: SQLite3 plugin

So, I thought it'd be a cool idea to have a robust persistent store with a simple Lua interface integrated within Maratis.

I'd like to learn more about pushing C++ values into Lua so that Maratis can access them and vice versa. How would this work for collections (arrays, hashtables, etc.)? I think figuring this out would help streamline games where you have to worry about a player's inventory, or related mechanics.

If there's some Maratis documentation that covers this specifically, please let me know. I'd love to learn more about it.

Thanks.

Last edited by sunnystormy (2014-02-04 18:31:37)

Re: SQLite3 plugin

A simple way is to create a function and send the array to the script context :

In your c++ plugin :

float myArray[100];

int getMyArray(void)
{
    MEngine * engine = MEngine::getInstance();
    MScriptContext * script = engine->getScriptContext();
    script->pushFloatArray(myArray, 100);
    return 1;
}

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

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

In lua :

myArray = getMyArray()

Re: SQLite3 plugin

Cool, but, I'm a little confused. : / ...in that instance, because you're pushing a "float" array, isn't the method expecting the values inside the collection to be floats? What about other types of arrays (like one containing strings)?

Last edited by sunnystormy (2014-02-04 22:32:48)

Re: SQLite3 plugin

Yes pushFloatArray require a float array.
There is no string array method implemented, you have the choice between :

pushIntArray(const int * values, unsigned int valuesNumber);
pushFloatArray(const float * values, unsigned int valuesNumber);
pushString(const char * string);
pushBoolean(bool value);
pushInteger(int value);
pushFloat(float value);
void pushPointer(void* value);

Re: SQLite3 plugin

Ah, okay. Seems like I'd have to get a little creative. smile

For my purposes, it looks like I'd have to enumerate through the collection of strings on the C++ side, push those strings into Lua, and at that point they can be enumerated into a table or something like that? I'm kind of half-guessing here... >_>

Thank you for letting me know.

Last edited by sunnystormy (2014-02-05 01:11:24)

Re: SQLite3 plugin

what does your data looks like ?
and how do you get the data ?

Re: SQLite3 plugin

I haven't written the classes yet, so I don't have any sample code to show. I think I'll hold off on posting any further about this until I have some tangible results.

Thanks for your help, Anael.