我在使用Lua 5.2函数从C++调用时遇到了问题.
这是Lua块(名为test.lua):
function testFunction ()
print "Hello World"
end
Run Code Online (Sandbox Code Playgroud)
这是C++:
int iErr = 0;
//Create a lua state
lua_State *lua = luaL_newstate();
// Load io library
luaopen_io (lua);
//load the chunk we want to execute (test.lua)
iErr = luaL_loadfile(lua, "test.lua");
if (iErr == 0) {
printf("successfully loaded test.lua\n");
// Push the function name onto the stack
lua_getglobal(lua, "testFunction");
printf("called lua_getglobal. lua stack height is now %d\n", lua_gettop(lua));
//Call our function
iErr = lua_pcall(lua, 0, 0, 0);
if (iErr != …Run Code Online (Sandbox Code Playgroud)