Crash when calling luabind function on object

那年仲夏 提交于 2019-12-11 14:43:17

问题


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:


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



来源:https://stackoverflow.com/questions/20450764/crash-when-calling-luabind-function-on-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!