Lua 5.2 LUA_GLOBALSINDEX Alternative
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);