在对对象调用luabind函数时崩溃 [英] Crash when calling luabind function on object
问题描述
当我试图从C ++(通过luabind)运行运行函数(在lua中定义)时,我得到以下错误:
在Game_Launcher.exe中的0x767BC41F处的未处理异常:Microsoft
C ++异常:luabind :: error在内存位置0x001BF8B8。
使用一些try / catch欺骗我得到了稍微没用的消息:
表达式:lua runtime error
表达式:运行
Lua:
本地函数Run(self)
self.ticks = self.ticks + 1
end
return {
ticks = 0,
Run = Run,
}
C ++: h3>
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);
//执行run函数
luaDataTable [Run](luaDataTable);
}
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);
//执行run函数
luaDataTable [Run](luaDataTable);
}
最好我可以告诉, luaDataTable
是一个表,并且有效。不知道我做错了什么!
如果我删除第一个pop状态,
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!
I appears if I remove the first pop state it works, oops!
这篇关于在对对象调用luabind函数时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!