diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-19 15:03:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-19 15:03:04 -0300 |
commit | 88f020b626d1b5b10b5d12e04bf103409a5e4308 (patch) | |
tree | e8d65e90ce914acebbd74c528b660db21ef27084 | |
parent | a38f093f0540bce0207bb2dc27f1779f41c6d48b (diff) | |
download | lua-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.c | 3 | ||||
-rw-r--r-- | lua.h | 6 | ||||
-rw-r--r-- | manual.tex | 17 | ||||
-rw-r--r-- | mathlib.c | 5 | ||||
-rw-r--r-- | opcode.c | 16 |
5 files changed, 25 insertions, 22 deletions
@@ -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 | } |
@@ -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 @@ | |||
21 | typedef void (*lua_CFunction) (void); | 21 | typedef void (*lua_CFunction) (void); |
22 | typedef unsigned int lua_Object; | 22 | typedef unsigned int lua_Object; |
23 | 23 | ||
24 | lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method); | 24 | lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ |
25 | lua_Object lua_gettagmethod (int tag, char *event); | 25 | lua_Object lua_gettagmethod (int tag, char *event); |
26 | lua_Object lua_seterrormethod (lua_CFunction method); | 26 | lua_Object lua_seterrormethod (void); /* In: new method */ |
27 | 27 | ||
28 | int lua_newtag (void); | 28 | int lua_newtag (void); |
29 | void lua_settag (int tag); /* In: object */ | 29 | void lua_settag (int tag); /* In: object */ |
@@ -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)|. | |||
1457 | The error handler method \see{error} can be changed with: | 1457 | The error handler method \see{error} can be changed with: |
1458 | \Deffunc{lua_seterrormethod} | 1458 | \Deffunc{lua_seterrormethod} |
1459 | \begin{verbatim} | 1459 | \begin{verbatim} |
1460 | lua_Object lua_seterrormethod (lua_CFunction method); | 1460 | lua_Object lua_seterrormethod (void); |
1461 | \end{verbatim} | 1461 | \end{verbatim} |
1462 | This function returns a \verb|lua_Object|, | 1462 | This function sets the object at the top of C2lua |
1463 | which is the old error method value. | 1463 | as the new error method, |
1464 | and returns the old error method value. | ||
1464 | 1465 | ||
1465 | Tag methods can be changed with: | 1466 | Tag methods can be changed with: |
1466 | \Deffunc{lua_settagmethod} | 1467 | \Deffunc{lua_settagmethod} |
1467 | \begin{verbatim} | 1468 | \begin{verbatim} |
1468 | lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method); | 1469 | lua_Object lua_settagmethod (int tag, char *event); |
1469 | \end{verbatim} | 1470 | \end{verbatim} |
1470 | The first parameter is the tag, | 1471 | The first parameter is the tag, |
1471 | the second is the event name \see{tag-method}, | 1472 | the second is the event name \see{tag-method}; |
1472 | and the third is a CFunction to be used as the new method. | 1473 | the new method is pushed from C2lua. |
1473 | This function returns a \verb|lua_Object|, | 1474 | This function returns a \verb|lua_Object|, |
1474 | which is the old tag method value. | 1475 | which is the old tag method value. |
1475 | To get just the current value of a tag method, | 1476 | To get just the current value of a tag method, |
@@ -3,7 +3,7 @@ | |||
3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mathlib="$Id: mathlib.c,v 1.23 1997/04/06 14:08:08 roberto Exp roberto $"; | 6 | char *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[] = { | |||
210 | void mathlib_open (void) | 210 | void 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 | ||
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 4.11 1997/06/16 19:48:18 roberto Exp roberto $"; | 6 | char *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 | ||
657 | lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method) | 657 | lua_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 | ||
669 | lua_Object lua_seterrormethod (lua_CFunction method) | 669 | lua_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 | } |