From 67c1afff5917b118f3be818dd0df7448d19de877 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 31 Oct 2000 11:10:24 -0200 Subject: [PATCH] lua_settagmethod does not return old tag method --- lbaselib.c | 5 ++++- liolib.c | 3 +-- lmathlib.c | 3 +-- ltests.c | 8 ++++++-- ltm.c | 7 ++----- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lbaselib.c b/lbaselib.c index e588f0c3..1973cb42 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.14 2000/10/24 19:19:15 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.15 2000/10/27 16:15:53 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -184,10 +184,13 @@ static int luaB_settagmethod (lua_State *L) { "function or nil expected"); if (strcmp(event, "gc") == 0) lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); + lua_gettagmethod(L, tag, event); + lua_pushvalue(L, 3); lua_settagmethod(L, tag, event); return 1; } + static int luaB_gettagmethod (lua_State *L) { int tag = luaL_check_int(L, 1); const char *event = luaL_check_string(L, 2); diff --git a/liolib.c b/liolib.c index 6693df33..4ef4c439 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.89 2000/10/26 12:53:55 roberto Exp roberto $ +** $Id: liolib.c,v 1.90 2000/10/27 16:15:53 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -708,7 +708,6 @@ static void openwithcontrol (lua_State *L) { /* close files when collected */ lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */ lua_settagmethod(L, ctrl->iotag, "gc"); - lua_pop(L, 1); /* remove tag method returned by previous call */ } diff --git a/lmathlib.c b/lmathlib.c index 19e0c5ac..0f08866a 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.30 2000/10/26 12:47:05 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.31 2000/10/27 16:15:53 roberto Exp roberto $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -232,7 +232,6 @@ LUALIB_API void lua_mathlibopen (lua_State *L) { luaL_openl(L, mathlib); lua_pushcfunction(L, math_pow); lua_settagmethod(L, LUA_TNUMBER, "pow"); - lua_pop(L, 1); /* remove result from previous call */ lua_pushnumber(L, PI); lua_setglobal(L, "PI"); } diff --git a/ltests.c b/ltests.c index b45a1de2..a80a7977 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 1.52 2000/10/26 12:47:05 roberto Exp roberto $ +** $Id: ltests.c,v 1.53 2000/10/30 16:29:59 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -322,8 +322,12 @@ static int doremote (lua_State *L) { } static int settagmethod (lua_State *L) { + int tag = luaL_check_int(L, 1); + const char *event = luaL_check_string(L, 2); luaL_checkany(L, 3); - lua_settagmethod(L, luaL_check_int(L, 1), luaL_check_string(L, 2)); + lua_gettagmethod(L, tag, event); + lua_pushvalue(L, 3); + lua_settagmethod(L, tag, event); return 1; } diff --git a/ltm.c b/ltm.c index ce4fd89a..14dbe772 100644 --- a/ltm.c +++ b/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 1.54 2000/10/05 13:00:17 roberto Exp roberto $ +** $Id: ltm.c,v 1.55 2000/10/20 16:39:03 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -141,7 +141,6 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { - Closure *oldtm; int e = luaI_checkevent(L, event, t); checktag(L, t); if (!luaT_validevent(t, e)) @@ -149,7 +148,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { luaT_eventname[e], luaO_typenames[t], (t == LUA_TTABLE || t == LUA_TUSERDATA) ? " with default tag" : ""); - oldtm = luaT_gettm(L, t, e); switch (ttype(L->top - 1)) { case LUA_TNIL: luaT_gettm(L, t, e) = NULL; @@ -160,7 +158,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { default: lua_error(L, "tag method must be a function (or nil)"); } - clvalue(L->top - 1) = oldtm; - ttype(L->top - 1) = (oldtm ? LUA_TFUNCTION : LUA_TNIL); + L->top--; }