小编use*_*503的帖子

Lua 5.2问题:'尝试从lua_pcall调用一个nil值'

我在使用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)

c++ lua lua-5.2

6
推荐指数
1
解决办法
3283
查看次数

标签 统计

c++ ×1

lua ×1

lua-5.2 ×1