aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-12 15:27:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-12 15:27:29 -0300
commit611680af08b6102bd260068d9c9ad6961029bd5d (patch)
tree2ba7bbe708f5bcb7250afff601578392ac00da86
parentcb1d8f0fa014b0f94e09500d71aaff98fa197d19 (diff)
downloadlua-611680af08b6102bd260068d9c9ad6961029bd5d.tar.gz
lua-611680af08b6102bd260068d9c9ad6961029bd5d.tar.bz2
lua-611680af08b6102bd260068d9c9ad6961029bd5d.zip
functions "lua_settagmethod" and similars should be safe too.
-rw-r--r--lua.h9
-rw-r--r--opcode.c26
2 files changed, 18 insertions, 17 deletions
diff --git a/lua.h b/lua.h
index d183832f..e255045b 100644
--- a/lua.h
+++ b/lua.h
@@ -2,7 +2,7 @@
2** LUA - An Extensible Extension Language 2** LUA - An Extensible Extension Language
3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
4** e-mail: lua@tecgraf.puc-rio.br 4** e-mail: lua@tecgraf.puc-rio.br
5** $Id: lua.h,v 4.5 1997/06/06 20:54:40 roberto Exp roberto $ 5** $Id: lua.h,v 4.6 1997/06/09 17:28:14 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -21,8 +21,8 @@
21typedef void (*lua_CFunction) (void); 21typedef void (*lua_CFunction) (void);
22typedef unsigned int lua_Object; 22typedef unsigned int lua_Object;
23 23
24void lua_settagmethod (int tag, char *event, lua_CFunction method); 24lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method);
25void lua_gettagmethod (int tag, char *event); /* out: method */ 25lua_Object lua_gettagmethod (int tag, char *event);
26void lua_seterrormethod (lua_CFunction method); 26void lua_seterrormethod (lua_CFunction method);
27 27
28int lua_newtag (void); 28int lua_newtag (void);
@@ -81,9 +81,6 @@ void lua_unref (int ref);
81 81
82lua_Object lua_createtable (void); 82lua_Object lua_createtable (void);
83 83
84lua_Object lua_getudata (void *u, int tag);
85
86
87long lua_collectgarbage (long limit); 84long lua_collectgarbage (long limit);
88 85
89 86
diff --git a/opcode.c b/opcode.c
index b51598ea..84b69c80 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.6 1997/06/06 20:54:40 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.7 1997/06/09 17:28:14 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -552,13 +552,14 @@ static void do_callinc (int nResults)
552 CLS_current.base = base + CLS_current.num; /* incorporate results on stack */ 552 CLS_current.base = base + CLS_current.num; /* incorporate results on stack */
553} 553}
554 554
555
555static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) 556static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults)
556{ 557{
557 adjustC(nParams); 558 StkId base = (top-stack)-nParams;
558 open_stack((top-stack)-CLS_current.base); 559 open_stack(nParams);
559 stack[CLS_current.base].ttype = LUA_T_CFUNCTION; 560 stack[base].ttype = LUA_T_CFUNCTION;
560 stack[CLS_current.base].value.f = f; 561 stack[base].value.f = f;
561 do_callinc(nResults); 562 do_call(base+1, nResults);
562} 563}
563 564
564 565
@@ -687,17 +688,18 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback)
687 lua_pushstring(name); 688 lua_pushstring(name);
688 lua_pushcfunction(fallback); 689 lua_pushcfunction(fallback);
689 do_unprotectedrun(luaI_setfallback, 2, 1); 690 do_unprotectedrun(luaI_setfallback, 2, 1);
690 return (Ref(top-1)); 691 return put_luaObjectonTop();
691} 692}
692 693
693void lua_gettagmethod (int tag, char *event) 694lua_Object lua_gettagmethod (int tag, char *event)
694{ 695{
695 lua_pushnumber(tag); 696 lua_pushnumber(tag);
696 lua_pushstring(event); 697 lua_pushstring(event);
697 do_unprotectedrun(luaI_gettagmethod, 2, 1); 698 do_unprotectedrun(luaI_gettagmethod, 2, 1);
699 return put_luaObjectonTop();
698} 700}
699 701
700void lua_settagmethod (int tag, char *event, lua_CFunction method) 702lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method)
701{ 703{
702 lua_pushnumber(tag); 704 lua_pushnumber(tag);
703 lua_pushstring(event); 705 lua_pushstring(event);
@@ -706,11 +708,12 @@ void lua_settagmethod (int tag, char *event, lua_CFunction method)
706 else 708 else
707 lua_pushnil(); 709 lua_pushnil();
708 do_unprotectedrun(luaI_settagmethod, 3, 1); 710 do_unprotectedrun(luaI_settagmethod, 3, 1);
711 return put_luaObjectonTop();
709} 712}
710 713
711void lua_seterrormethod (lua_CFunction method) 714void lua_seterrormethod (lua_CFunction method)
712{ 715{
713 lua_pushcfunction (method); 716 lua_pushcfunction(method);
714 do_unprotectedrun(luaI_seterrormethod, 1, 0); 717 do_unprotectedrun(luaI_seterrormethod, 1, 0);
715} 718}
716 719
@@ -992,7 +995,8 @@ void lua_pushcfunction (lua_CFunction fn)
992 995
993void lua_pushusertag (void *u, int tag) 996void lua_pushusertag (void *u, int tag)
994{ 997{
995 if (tag < 0) luaI_realtag(tag); /* error if tag is not valid */ 998 if (tag < 0 && tag != LUA_ANYTAG)
999 luaI_realtag(tag); /* error if tag is not valid */
996 tsvalue(top) = luaI_createudata(u, tag); 1000 tsvalue(top) = luaI_createudata(u, tag);
997 ttype(top) = LUA_T_USERDATA; 1001 ttype(top) = LUA_T_USERDATA;
998 incr_top; 1002 incr_top;