Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top