我得到了以下代码,它工作得很好,并且完全按照我想要的Lua 5.1,但是尝试将其移植到5.2(并且缺少LUA_GLOBALSINDEX)我有问题...任何人都可以告诉我什么相当于:
thread->L = lua_newthread( G );
lua_pushvalue( G, -1 );
thread->index = luaL_ref( G, LUA_REGISTRYINDEX );
lua_newtable( thread->L );
lua_newtable( thread->L );
lua_pushliteral( thread->L, "__index" );
-- Problem... no more LUA_GLOBALSINDEX, cannot find equivalent for push.
lua_pushvalue( thread->L, LUA_GLOBALSINDEX );
lua_settable( thread->L, -3 );
lua_setmetatable( thread->L, -2 );
-- Problem... no more LUA_GLOBALSINDEX, cannot find equivalent for replace.
lua_replace( thread->L, LUA_GLOBALSINDEX );
在Lua 5.2中?
韩国社交协会!
答案 0 :(得分:2)
您应该使用lua_pushglobaltable(thead->L)
(或者如果必须,lua_rawgeti(thread->L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
。Lua 5.2 LUA_GLOBALSINDEX Alternative的接受答案中对此进行了解释。