问题描述
在代码示例中: http://lua-users.org/wiki/SimplerCppBinding
有代码:
lua_pushstring(L, T::className);
lua_pushvalue(L, methods);
lua_settable(L, LUA_GLOBALSINDEX); //<--- LUA_GLOBALSINDEX removed in Lua 5.2
lua_pushliteral(L, "__metatable");
lua_pushvalue(L, methods);
lua_settable(L, metatable);
在Lua 5.2中,LUA_GLOBALSINDEX不再存在.相反,它具有lua_setglobal()和lua_getglobal().
In Lua 5.2, LUA_GLOBALSINDEX no longer exists. Instead, it has lua_setglobal() and lua_getglobal().
我是否正确地认为:
lua_pushvalue(L, methods);
lua_setglobal(L, T::className);
...是以下各项的正确替代品
...is the correct replacement for:
lua_pushstring(L, T::className);
lua_pushvalue(L, methods);
lua_settable(L, LUA_GLOBALSINDEX);
我对Lua来说还太陌生,无法确定,我已经8个月没有使用它了.查看文档,我认为这是正确的,但需要验证.
I'm too new to Lua to be sure, I haven't used it for 8 months. Looking at the documentation, I'm thinking this is correct, but would like verification.
推荐答案
使用lua_setglobal(L,T::className);
代替lua_settable(L,LUA_GLOBALSINDEX);
.在Lua 5.1和5.2中都可以使用.
Instead of lua_settable(L,LUA_GLOBALSINDEX);
use lua_setglobal(L,T::className);
. That works in both Lua 5.1 and 5.2.
这篇关于移植到Lua 5.2,LUA_GLOBALSINDEX麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!