aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-19 15:03:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-19 15:03:04 -0300
commit88f020b626d1b5b10b5d12e04bf103409a5e4308 (patch)
treee8d65e90ce914acebbd74c528b660db21ef27084
parenta38f093f0540bce0207bb2dc27f1779f41c6d48b (diff)
downloadlua-88f020b626d1b5b10b5d12e04bf103409a5e4308.tar.gz
lua-88f020b626d1b5b10b5d12e04bf103409a5e4308.tar.bz2
lua-88f020b626d1b5b10b5d12e04bf103409a5e4308.zip
new interface to "lua_seterrormethod" and "lua_settagmethod", to
allow the use of Lua functions too.
-rw-r--r--iolib.c3
-rw-r--r--lua.h6
-rw-r--r--manual.tex17
-rw-r--r--mathlib.c5
-rw-r--r--opcode.c16
5 files changed, 25 insertions, 22 deletions
diff --git a/iolib.c b/iolib.c
index 8a531e50..3a532c8a 100644
--- a/iolib.c
+++ b/iolib.c
@@ -302,5 +302,6 @@ void iolib_open (void)
302 lua_tagio = lua_newtag(); 302 lua_tagio = lua_newtag();
303 lua_infile=stdin; lua_outfile=stdout; 303 lua_infile=stdin; lua_outfile=stdout;
304 luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); 304 luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
305 lua_seterrormethod(errorfb); 305 lua_pushcfunction(errorfb);
306 lua_seterrormethod();
306} 307}
diff --git a/lua.h b/lua.h
index 9b1e8dce..cc5ed897 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.8 1997/06/16 19:48:18 roberto Exp roberto $ 5** $Id: lua.h,v 4.9 1997/06/18 21:20:45 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -21,9 +21,9 @@
21typedef void (*lua_CFunction) (void); 21typedef void (*lua_CFunction) (void);
22typedef unsigned int lua_Object; 22typedef unsigned int lua_Object;
23 23
24lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method); 24lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
25lua_Object lua_gettagmethod (int tag, char *event); 25lua_Object lua_gettagmethod (int tag, char *event);
26lua_Object lua_seterrormethod (lua_CFunction method); 26lua_Object lua_seterrormethod (void); /* In: new method */
27 27
28int lua_newtag (void); 28int lua_newtag (void);
29void lua_settag (int tag); /* In: object */ 29void lua_settag (int tag); /* In: object */
diff --git a/manual.tex b/manual.tex
index 6e6d524e..2d19ac88 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 2.1 1997/06/18 20:14:52 roberto Exp roberto $ 1% $Id: manual.tex,v 2.2 1997/06/18 21:11:53 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -38,7 +38,7 @@ Waldemar Celes
38\tecgraf\ --- Computer Science Department --- PUC-Rio 38\tecgraf\ --- Computer Science Department --- PUC-Rio
39} 39}
40 40
41\date{\small \verb$Date: 1997/06/18 20:14:52 $} 41\date{\small \verb$Date: 1997/06/18 21:11:53 $}
42 42
43\maketitle 43\maketitle
44 44
@@ -1457,19 +1457,20 @@ Otherwise, the whole program terminates with a call to \verb|exit(1)|.
1457The error handler method \see{error} can be changed with: 1457The error handler method \see{error} can be changed with:
1458\Deffunc{lua_seterrormethod} 1458\Deffunc{lua_seterrormethod}
1459\begin{verbatim} 1459\begin{verbatim}
1460lua_Object lua_seterrormethod (lua_CFunction method); 1460lua_Object lua_seterrormethod (void);
1461\end{verbatim} 1461\end{verbatim}
1462This function returns a \verb|lua_Object|, 1462This function sets the object at the top of C2lua
1463which is the old error method value. 1463as the new error method,
1464and returns the old error method value.
1464 1465
1465Tag methods can be changed with: 1466Tag methods can be changed with:
1466\Deffunc{lua_settagmethod} 1467\Deffunc{lua_settagmethod}
1467\begin{verbatim} 1468\begin{verbatim}
1468lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method); 1469lua_Object lua_settagmethod (int tag, char *event);
1469\end{verbatim} 1470\end{verbatim}
1470The first parameter is the tag, 1471The first parameter is the tag,
1471the second is the event name \see{tag-method}, 1472the second is the event name \see{tag-method};
1472and the third is a CFunction to be used as the new method. 1473the new method is pushed from C2lua.
1473This function returns a \verb|lua_Object|, 1474This function returns a \verb|lua_Object|,
1474which is the old tag method value. 1475which is the old tag method value.
1475To get just the current value of a tag method, 1476To get just the current value of a tag method,
diff --git a/mathlib.c b/mathlib.c
index 17e301da..bb33db08 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
3** Mathematics library to LUA 3** Mathematics library to LUA
4*/ 4*/
5 5
6char *rcs_mathlib="$Id: mathlib.c,v 1.23 1997/04/06 14:08:08 roberto Exp roberto $"; 6char *rcs_mathlib="$Id: mathlib.c,v 1.24 1997/06/09 17:30:10 roberto Exp roberto $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <math.h> 9#include <math.h>
@@ -210,7 +210,8 @@ static struct luaL_reg mathlib[] = {
210void mathlib_open (void) 210void mathlib_open (void)
211{ 211{
212 luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); 212 luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
213 lua_pushcfunction(math_pow);
213 lua_pushnumber(0); /* to get its tag */ 214 lua_pushnumber(0); /* to get its tag */
214 lua_settagmethod(lua_tag(lua_pop()), "pow", math_pow); 215 lua_settagmethod(lua_tag(lua_pop()), "pow");
215} 216}
216 217
diff --git a/opcode.c b/opcode.c
index d373dcec..982b1da9 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.11 1997/06/16 19:48:18 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.12 1997/06/19 17:46:12 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -654,21 +654,21 @@ lua_Object lua_gettagmethod (int tag, char *event)
654 return put_luaObjectonTop(); 654 return put_luaObjectonTop();
655} 655}
656 656
657lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method) 657lua_Object lua_settagmethod (int tag, char *event)
658{ 658{
659 TObject newmethod;
660 checkCparams(1);
661 newmethod = *(--top);
659 lua_pushnumber(tag); 662 lua_pushnumber(tag);
660 lua_pushstring(event); 663 lua_pushstring(event);
661 if (method) 664 *top = newmethod; incr_top;
662 lua_pushcfunction (method);
663 else
664 lua_pushnil();
665 do_unprotectedrun(luaI_settagmethod, 3, 1); 665 do_unprotectedrun(luaI_settagmethod, 3, 1);
666 return put_luaObjectonTop(); 666 return put_luaObjectonTop();
667} 667}
668 668
669lua_Object lua_seterrormethod (lua_CFunction method) 669lua_Object lua_seterrormethod (void)
670{ 670{
671 lua_pushcfunction(method); 671 checkCparams(1);
672 do_unprotectedrun(luaI_seterrormethod, 1, 1); 672 do_unprotectedrun(luaI_seterrormethod, 1, 1);
673 return put_luaObjectonTop(); 673 return put_luaObjectonTop();
674} 674}