user3192607
user3192607

Reputation: 41

Porting Lua 5.1 thread code to 5.2

I got the following code which work great and do exactly what I want in Lua 5.1, however trying to port that to 5.2 (and the lack of LUA_GLOBALSINDEX) Im having issues... Anybody can tell me what is the equivalent of:

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 );

in Lua 5.2?

Tks!

Upvotes: 2

Views: 473

Answers (1)

Oliver
Oliver

Reputation: 29493

You should use lua_pushglobaltable(thead->L) (or if you have to, lua_rawgeti(thread->L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS). This is explained in the accepted answer to Lua 5.2 LUA_GLOBALSINDEX Alternative.

Upvotes: 2

Related Questions