lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, everyone.
 
In my programme, I want to catch the index activity of the global table whenever it failed to get _G[name], so I can provide my userdata to that indexed global variable. But unfortunately I got a failure and I can't figure out the reason. Following is my code fragment:
 
    static int global_resovler(lua_State *L)
    {
   
        printf("global resolver\n");
        return 0;
    }
 
    // in the extension
    // Registers the global resolver
    lua_pushvalue(L, LUA_GLOBALSINDEX);
    lua_getmetatable(L, -1);
    
    lua_pushstring(L, "__index");
    lua_pushcfunction(L, global_resovler);
    lua_rawset(L, -3);
    lua_pushstring(L, "__newindex");
    lua_pushcfunction(L, global_resovler);
    lua_rawset(L, -3);
    lua_pop(L, 1);
 
Can anyone help me figure out why there's no output from the global_resolver when I index a global variable from the script ? Thanks!
--
Best Regards.

Chen guo
Tongji University, China