From 5c5d9b27031f0a7fcf61df86cd242105c38485d6 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 14 Nov 2002 10:01:35 -0200 Subject: back to `__mode' metafield to specify weakness --- lbaselib.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index 8753273a..c55d3e98 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.104 2002/11/06 19:08:00 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.105 2002/11/07 15:39:23 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -88,21 +88,6 @@ static int luaB_error (lua_State *L) { } -static int luaB_getmode (lua_State *L) { - luaL_check_type(L, 1, LUA_TTABLE); - lua_pushstring(L, lua_getmode(L, 1)); - return 1; -} - - -static int luaB_setmode (lua_State *L) { - luaL_check_type(L, 1, LUA_TTABLE); - lua_setmode(L, 1, luaL_check_string(L, 2)); - lua_settop(L, 1); - return 1; -} - - static int luaB_getmetatable (lua_State *L) { luaL_check_any(L, 1); if (!lua_getmetatable(L, 1)) { @@ -524,8 +509,6 @@ static const luaL_reg base_funcs[] = { {"setmetatable", luaB_setmetatable}, {"getglobals", luaB_getglobals}, {"setglobals", luaB_setglobals}, - {"getmode", luaB_getmode}, - {"setmode", luaB_setmode}, {"next", luaB_next}, {"ipairs", luaB_ipairs}, {"pairs", luaB_pairs}, @@ -646,7 +629,11 @@ static void base_open (lua_State *L) { /* `newproxy' needs a weaktable as upvalue */ lua_pushliteral(L, "newproxy"); lua_newtable(L); /* new table `w' */ - lua_setmode(L, -1, "k"); + lua_pushvalue(L, -1); /* `w' will be its own metatable */ + lua_setmetatable(L, -2); + lua_pushliteral(L, "__mode"); + lua_pushliteral(L, "k"); + lua_rawset(L, -3); /* metatable(w).__mode = "k" */ lua_pushcclosure(L, luaB_newproxy, 1); lua_rawset(L, -3); /* set global `newproxy' */ lua_rawset(L, -1); /* set global _G */ -- cgit v1.2.3-55-g6feb