[英]lua function argument expected near <eof>
I try to use lua in a C++ project. 我尝试在C ++项目中使用lua。 For lua executing I write this:
为了执行lua,我将其编写为:
#include <lua.hpp>
...
luaEngine = luaL_newstate();
luaL_openlibs(luaEngine);
register_results(luaEngine); // For register c++ object in the LUA script as metatable
lua_pushstring(luaEngine, resultsId.c_str());
lua_setglobal(luaEngine, "resultsId");
lua_pushboolean(luaEngine, needReloadModel);
lua_setglobal(luaEngine, "needReload");
...
e = luaL_loadbuffer(luaEngine, script.c_str(), script.size(), NULL);
if(e != 0)
// error message
e = lua_pcall(luaEngine, 0, 1, 0);
if(e != 0)
// error message
...
lua_close(luaEngine);
And the lua script: 和lua脚本:
local Res = ResUpdateLUA(resultsId)
if current_result == "Normal" or current_result=='-' then
status = 'E'
else
status = 'O'
end
needReload = Res:setShowAnalyte('2320', status)
That didn't work and I've got error message: 那没有用,我收到错误消息:
[string "?"]:7: function arguments expected near <eof>
But when I add 但是当我添加
print(needReload)
at the end of the lua script it works nice. 在lua脚本的末尾,它很好用。 What am I doing wrong?
我究竟做错了什么?
The error message means that Lua reached the end of the source after seeing Res:s
but before seeing (
. 错误消息表示Lua在看到
Res:s
但在看到(
之前到达了源的结尾。
I suspect that script.size()
is wrong. 我怀疑
script.size()
错误。 But I can't explain why adding that line works. 但我无法解释为什么添加该行。
Thank you all for your answers. 谢谢大家的答案。 Yes, that was trouble with
script.size()
coz when it was replaced to e = luaL_loadbuffer(luaEngine, script.c_str(), strlen(script.c_str()), NULL);
是的,当将
script.size()
替换为e = luaL_loadbuffer(luaEngine, script.c_str(), strlen(script.c_str()), NULL);
时,这很麻烦e = luaL_loadbuffer(luaEngine, script.c_str(), strlen(script.c_str()), NULL);
that started work fine. 开始工作正常。 Sorry for my stupid question.
对不起,我的愚蠢问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.