【发布时间】:2018-10-11 02:38:50
【问题描述】:
目前我正在尝试将 Lua 脚本与主机 C++ 应用程序链接。对于我的 Lua 脚本,我所拥有的只是:
io.write(string.format("From Lua."));
我为此使用 Qt 创建器并尝试像这样调用脚本:
lua_State *state = luaL_newstate();
lua_call(state , 0 , 0);
这一直给我一个PANIC: unprotected error in call to Lua API (attempt to call a string value) 错误。
我尝试将脚本包装在这样的函数中:
function main()
io.write(string.format("From Lua.With Progress"));
end
然后使用与之前相同的代码调用它,但添加:
lua_getglobal(state , "main");
lua_pcall(state , 0 , 0 , 0);
没有错误但是:
lua_call(state , 0 , 0)
给出PANIC: unprotected error in call to Lua API (attempt to call a nil value) 错误。
经过更多的故障排除后,我发现luaL_loadfile(state , "EngineRxer.lua") 返回的值是 7 而不是 0,所以我假设脚本首先加载失败。
我还在 Qt Creator projects -> Build and run ->run 中检查了我的运行工作目录,它们与 Lua 脚本位于同一目录中。
我提到过:
Qt with Lua | Where to place lua file(s)
甚至一些 Qt 论坛:
http://www.qtcentre.org/threads/60693-Can-not-use-Lua-in-QtCreator
http://www.qtcentre.org/threads/62772-Lua-into-Qt
另外,提一下我的 .pro 文件的样子可能很重要,所有 Lua 库和包含都已经在其中:
LIBS += \
/usr/local/Cellar/lua/5.3.4_3/lib/liblua.5.3.4.dylib
INCLUDEPATH += \
/usr/local/Cellar/lua/5.3.4_3/include
更重要的是,经过更多故障排除后,我决定在 Netbeans(NonQt 只是 CML)上创建一个虚拟测试项目,它运行良好。即使我尝试制作一个虚拟的fstream 程序来写入一个空的 .txt 文件,它也不知道在哪里可以找到它。所以我怀疑这是 Qt Creator 问题,但我的所有路径和构建目录都指向 CWD。p>
【问题讨论】:
标签: c++ qt lua qt-creator