调用luabind函数时对象崩溃。

当我试图从C ++(通过luabind)运行Lua中定义的“Run”函数时,我收到以下错误:

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

使用一些try / catch技巧,我得到了稍微不那么无用的消息:

Expression: lua运行时错误

Expression: Run

Lua:

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

return {
    ticks = 0,
    Run = Run,
}

C ++:

void ScriptComponent :: Initialize()
{
    //我把所有东西都通过文件系统传输,因此必须首先将脚本作为字符串加载
    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);

    //执行运行功能
    luaDataTable [“Run”](luaDataTable);
}

我最好能知道,luaDataTable是有效的表格。不确定我哪里做错了!

点赞
用户1072711
用户1072711

翻译

如果我删除第一个 pop state,它可以工作,哎呀!

原始内容

I appears if I remove the first pop state it works, oops!
2013-12-10 03:59:10