From fa19baab7ffd96cecb1defe4ad81084c612d2704 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Feb 2008 15:54:09 -0300 Subject: [PATCH] proxies must be created with a __gc field in their metatables to work properly with new semantics for finalizers --- lbaselib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lbaselib.c b/lbaselib.c index a6a674c7..a2d9cbb9 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.203 2008/02/11 19:14:52 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.204 2008/02/14 16:03:09 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -418,7 +418,9 @@ static int luaB_newproxy (lua_State *L) { if (lua_toboolean(L, 1) == 0) return 1; /* no metatable */ else if (lua_isboolean(L, 1)) { - lua_newtable(L); /* create a new metatable `m' ... */ + lua_createtable(L, 0, 1); /* create a new metatable `m' ... */ + lua_pushboolean(L, 1); + lua_setfield(L, -2, "__gc"); /* ... m.__gc = false (HACK!!)... */ lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */ lua_pushboolean(L, 1); lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */