title: Lua 5.2 LUA_GLOBALSINDEX Alternative
body: <p>I have a program that embeds Lua and implements a form of lazy function lookup.</p>
  
  <p>The way it worked in Lua 5.1, whenever a symbol was undefined the interpreter would call a global function hook that would then resolve the symbol.</p>
  
  <p>This is a small portion of C code that implemented this lazy function lookup:</p>
  
  <pre><code>int function_hook(lua_State *pLuaState)
  {
    // do the function lookup here
    ....
    return 1;
  }
  
  ......
  
  //-- 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, LUA_GLOBALSINDEX);
  </code></pre>
  
  <p>I'm now trying to move this code to Lua 5.2 and have run into a problem.</p>
  
  <p>In Lua 5.2 the LUA_GLOBALSINDEX value is no longer defined so this line of code no longer compiles.</p>
  
  <pre><code>//-- set global call back hook
  lua_setmetatable(pLuaState, LUA_GLOBALSINDEX);
  </code></pre>
  
  <p>There is a <a href="http://www.lua.org/manual/5.2/" rel="noreferrer">reference</a> to this change to LUA_GLOBALSINDEX but unfortunately it has not helped.</p>
  
  <p>What would be the best way to re-write this one line of code to have the interpreter call the function_hook whenever it finds an unresolved symbol?</p>