且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Lua的5.2 LUA_GLOBALSINDEX替代

更新时间:2023-02-21 09:36:42

环境现在存储在该注册表一个特殊的指数。尝试:

The global environment is now stored at a special index in the registry. Try:

//-- get global environment table from registry
lua_rawgeti(pLuaState, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);

//-- create table containing the hook details
lua_newtable(pLuaState);
lua_pushstring(pLuaState, "__index");
lua_pushcfunction(pLuaState, function_hook);
lua_settable(pLuaState, -3);

//-- set global index callback hook
lua_setmetatable(pLuaState, -2);

//-- remove the global environment table from the stack
lua_pop(pLuaState, 1);