本文介绍了在对对象调用luabind函数时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图从C ++(通过luabind)运行运行函数(在lua中定义)时,我得到以下错误:

使用一些try / catch欺骗我得到了稍微没用的消息:



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);
}



最好我可以告诉, luaDataTable 是一个表,并且有效。不知道我做错了什么!

解决方案

如果我删除第一个pop状态,

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

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

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函数时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:35