Crash when calling luabind function on object

528 views Asked by At

When I try to run the "Run" function (defined in lua) from C++ (through luabind), I get the following error:

Unhandled exception at at 0x767BC41F in Game_Launcher.exe: Microsoft C++ exception: luabind::error at memory location 0x001BF8B8.

Using some try/catch trickery I got the slightly less useless messages of:

Expression: lua runtime error

Expression: Run

Lua:

local function Run(self)
    self.ticks = self.ticks + 1
end

return {
    ticks = 0,
    Run = Run,
}

C++:

void ScriptComponent::Initialize()
{
    // I pipe everything through a filesystem, so the script must be loaded as a string first
    String fileData;
    fileSystem->LoadFromFile("myscript.lua", filedata);

    int err = lual_loadstring(L, fileData);
    luabind::object compiledScript(luabind::from_stack(L, -1));
    lua_pop(luaState, 1);
    luabind::object luaDataTable = compiledScript();
    lua_pop(luaState, 1);

    // Execute the run function
    luaDataTable["Run"](luaDataTable);
}

Best I can tell, the luaDataTable is a table and is valid. Not sure what I did wrong!

1

There are 1 answers

0
MintyAnt On BEST ANSWER

I appears if I remove the first pop state it works, oops!