call(S, 0, 0) won't work (attempted to call a string value)?
So, I wanted to go ahead and add Lua scripting to my C++ game engine, however I can't seem to do it.
I'm watching a video and i have checked out the tiny bit of code and I can't see what I'm doing wrong.
#include <Lua Sourcelua.hpp>
lua_State* S = luaL_newstate();
luaL_openlibs(S);
luaL_loadfile(S, "main.lua");
lua_call(S, 0, 0);
The Lua source codes and files are all in my project folder, except for 2 cpp files which were main function (deleted those).
And my Lua file looks like this : (and is placed where the Lua source code is.)
print("Hello World")
The error I get looks like this :
In console :
PANIC : unprotected error in call to Lua API (attempt to call a string value)
This is what the error box that comes up looks like :
(Buttons form left to right : Cancel, Try Again, Ignore)
Error Box Link
Edits :
My code now looks like this, adding the puts(lua_tostring(S, -1));
generated a error message :
cannot open main.lua: no such file or directory
Code
lua_State* S = luaL_newstate();
luaL_openlibs(S);
luaL_loadfile(S, "main.lua");
puts(lua_tostring(S, -1));
lua_call(S, 0, 0);
And my project files like this :
Image of project files
attempt to call a string value
is triggered by lua_call
and most probably means that luaL_loadfile
returned non-zero and left an error message on the stack.
Check the return code of luaL_loadfile
.
Also, add puts(lua_tostring(S,-1));
after calling luaL_loadfile
.
Turns out I just misunderstood a tutorial.
Thought he meant that the lua scripts run out of lua's own source code folder...
But, it runs out of your project working directory.
链接地址: http://www.djcxy.com/p/95462.html上一篇: 子弹物理引擎,如何冻结一个对象?