`newproxy' uses its own weaktable
This commit is contained in:
20
lauxlib.c
20
lauxlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.76 2002/06/25 19:15:21 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.77 2002/06/26 19:28:44 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -302,24 +302,6 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_weakregistry (lua_State *L) {
|
||||
static const char dummy = '\0'; /* index for a weak table in registry */
|
||||
lua_pushudataval(L, (void *)&dummy); /* push index */
|
||||
lua_rawget(L, LUA_REGISTRYINDEX); /* get value */
|
||||
if (!lua_isnil(L, -1)) return; /* weak table already created? */
|
||||
/* else must create a weak table */
|
||||
lua_pop(L, 1); /* remove previous nil */
|
||||
lua_newtable(L); /* new table `w' */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setmetatable(L, -2); /* setmetatable(w, w) */
|
||||
lua_pushliteral(L, "__mode");
|
||||
lua_pushliteral(L, "kv");
|
||||
lua_rawset(L, -3); /* metatable(w).__mode = "kv" */
|
||||
lua_pushudataval(L, (void *)&dummy); /* push index */
|
||||
lua_pushvalue(L, -2); /* push value */
|
||||
lua_rawset(L, LUA_REGISTRYINDEX); /* store new weak table into registry */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
|
||||
Reference in New Issue
Block a user