lua_newtable(sl_gstate); // the global metatable lua_pushcfunction(sl_gstate, typel_mtindex); lua_setfield(sl_gstate, -2, "__index"); lua_pushcfunction(sl_gstate, typel_mtnewindex); lua_setfield(sl_gstate, -2, "__newindex"); lua_pushcfunction(sl_gstate, typel_mtgc); lua_setfield(sl_gstate, -2, "__gc"); typel_mtref = luaL_ref(sl_gstate, LUA_REGISTRYINDEX);