aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-31 11:10:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-31 11:10:24 -0200
commit67c1afff5917b118f3be818dd0df7448d19de877 (patch)
tree10b60153e85947af9a1791148b145e0dca82775d
parent03770ecfc91718f7a208995adb1f9fd5d8e0c85e (diff)
downloadlua-67c1afff5917b118f3be818dd0df7448d19de877.tar.gz
lua-67c1afff5917b118f3be818dd0df7448d19de877.tar.bz2
lua-67c1afff5917b118f3be818dd0df7448d19de877.zip
lua_settagmethod does not return old tag method
-rw-r--r--lbaselib.c5
-rw-r--r--liolib.c3
-rw-r--r--lmathlib.c3
-rw-r--r--ltests.c8
-rw-r--r--ltm.c7
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 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.14 2000/10/24 19:19:15 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.15 2000/10/27 16:15:53 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -184,10 +184,13 @@ static int luaB_settagmethod (lua_State *L) {
184 "function or nil expected"); 184 "function or nil expected");
185 if (strcmp(event, "gc") == 0) 185 if (strcmp(event, "gc") == 0)
186 lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua"); 186 lua_error(L, "deprecated use: cannot set the `gc' tag method from Lua");
187 lua_gettagmethod(L, tag, event);
188 lua_pushvalue(L, 3);
187 lua_settagmethod(L, tag, event); 189 lua_settagmethod(L, tag, event);
188 return 1; 190 return 1;
189} 191}
190 192
193
191static int luaB_gettagmethod (lua_State *L) { 194static int luaB_gettagmethod (lua_State *L) {
192 int tag = luaL_check_int(L, 1); 195 int tag = luaL_check_int(L, 1);
193 const char *event = luaL_check_string(L, 2); 196 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 @@
1/* 1/*
2** $Id: liolib.c,v 1.89 2000/10/26 12:53:55 roberto Exp roberto $ 2** $Id: liolib.c,v 1.90 2000/10/27 16:15:53 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -708,7 +708,6 @@ static void openwithcontrol (lua_State *L) {
708 /* close files when collected */ 708 /* close files when collected */
709 lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */ 709 lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */
710 lua_settagmethod(L, ctrl->iotag, "gc"); 710 lua_settagmethod(L, ctrl->iotag, "gc");
711 lua_pop(L, 1); /* remove tag method returned by previous call */
712} 711}
713 712
714 713
diff --git a/lmathlib.c b/lmathlib.c
index 19e0c5ac..0f08866a 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.30 2000/10/26 12:47:05 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.31 2000/10/27 16:15:53 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -232,7 +232,6 @@ LUALIB_API void lua_mathlibopen (lua_State *L) {
232 luaL_openl(L, mathlib); 232 luaL_openl(L, mathlib);
233 lua_pushcfunction(L, math_pow); 233 lua_pushcfunction(L, math_pow);
234 lua_settagmethod(L, LUA_TNUMBER, "pow"); 234 lua_settagmethod(L, LUA_TNUMBER, "pow");
235 lua_pop(L, 1); /* remove result from previous call */
236 lua_pushnumber(L, PI); 235 lua_pushnumber(L, PI);
237 lua_setglobal(L, "PI"); 236 lua_setglobal(L, "PI");
238} 237}
diff --git a/ltests.c b/ltests.c
index b45a1de2..a80a7977 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.52 2000/10/26 12:47:05 roberto Exp roberto $ 2** $Id: ltests.c,v 1.53 2000/10/30 16:29:59 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -322,8 +322,12 @@ static int doremote (lua_State *L) {
322} 322}
323 323
324static int settagmethod (lua_State *L) { 324static int settagmethod (lua_State *L) {
325 int tag = luaL_check_int(L, 1);
326 const char *event = luaL_check_string(L, 2);
325 luaL_checkany(L, 3); 327 luaL_checkany(L, 3);
326 lua_settagmethod(L, luaL_check_int(L, 1), luaL_check_string(L, 2)); 328 lua_gettagmethod(L, tag, event);
329 lua_pushvalue(L, 3);
330 lua_settagmethod(L, tag, event);
327 return 1; 331 return 1;
328} 332}
329 333
diff --git a/ltm.c b/ltm.c
index ce4fd89a..14dbe772 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.54 2000/10/05 13:00:17 roberto Exp roberto $ 2** $Id: ltm.c,v 1.55 2000/10/20 16:39:03 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -141,7 +141,6 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) {
141 141
142 142
143LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { 143LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
144 Closure *oldtm;
145 int e = luaI_checkevent(L, event, t); 144 int e = luaI_checkevent(L, event, t);
146 checktag(L, t); 145 checktag(L, t);
147 if (!luaT_validevent(t, e)) 146 if (!luaT_validevent(t, e))
@@ -149,7 +148,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
149 luaT_eventname[e], luaO_typenames[t], 148 luaT_eventname[e], luaO_typenames[t],
150 (t == LUA_TTABLE || t == LUA_TUSERDATA) ? 149 (t == LUA_TTABLE || t == LUA_TUSERDATA) ?
151 " with default tag" : ""); 150 " with default tag" : "");
152 oldtm = luaT_gettm(L, t, e);
153 switch (ttype(L->top - 1)) { 151 switch (ttype(L->top - 1)) {
154 case LUA_TNIL: 152 case LUA_TNIL:
155 luaT_gettm(L, t, e) = NULL; 153 luaT_gettm(L, t, e) = NULL;
@@ -160,7 +158,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) {
160 default: 158 default:
161 lua_error(L, "tag method must be a function (or nil)"); 159 lua_error(L, "tag method must be a function (or nil)");
162 } 160 }
163 clvalue(L->top - 1) = oldtm; 161 L->top--;
164 ttype(L->top - 1) = (oldtm ? LUA_TFUNCTION : LUA_TNIL);
165} 162}
166 163