commit 88f020b626d1b5b10b5d12e04bf103409a5e4308
parent a38f093f0540bce0207bb2dc27f1779f41c6d48b
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 19 Jun 1997 15:02:44 -0300
new interface to "lua_seterrormethod" and "lua_settagmethod", to
allow the use of Lua functions too.
Diffstat:
5 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/iolib.c b/iolib.c
@@ -302,5 +302,6 @@ void iolib_open (void)
lua_tagio = lua_newtag();
lua_infile=stdin; lua_outfile=stdout;
luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
- lua_seterrormethod(errorfb);
+ lua_pushcfunction(errorfb);
+ lua_seterrormethod();
}
diff --git a/lua.h b/lua.h
@@ -2,7 +2,7 @@
** LUA - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
-** $Id: lua.h,v 4.8 1997/06/16 19:48:18 roberto Exp roberto $
+** $Id: lua.h,v 4.9 1997/06/18 21:20:45 roberto Exp roberto $
*/
@@ -21,9 +21,9 @@
typedef void (*lua_CFunction) (void);
typedef unsigned int lua_Object;
-lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method);
+lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
lua_Object lua_gettagmethod (int tag, char *event);
-lua_Object lua_seterrormethod (lua_CFunction method);
+lua_Object lua_seterrormethod (void); /* In: new method */
int lua_newtag (void);
void lua_settag (int tag); /* In: object */
diff --git a/manual.tex b/manual.tex
@@ -1,4 +1,4 @@
-% $Id: manual.tex,v 2.1 1997/06/18 20:14:52 roberto Exp roberto $
+% $Id: manual.tex,v 2.2 1997/06/18 21:11:53 roberto Exp roberto $
\documentstyle[fullpage,11pt,bnf]{article}
@@ -38,7 +38,7 @@ Waldemar Celes
\tecgraf\ --- Computer Science Department --- PUC-Rio
}
-\date{\small \verb$Date: 1997/06/18 20:14:52 $}
+\date{\small \verb$Date: 1997/06/18 21:11:53 $}
\maketitle
@@ -1457,19 +1457,20 @@ Otherwise, the whole program terminates with a call to \verb|exit(1)|.
The error handler method \see{error} can be changed with:
\Deffunc{lua_seterrormethod}
\begin{verbatim}
-lua_Object lua_seterrormethod (lua_CFunction method);
+lua_Object lua_seterrormethod (void);
\end{verbatim}
-This function returns a \verb|lua_Object|,
-which is the old error method value.
+This function sets the object at the top of C2lua
+as the new error method,
+and returns the old error method value.
Tag methods can be changed with:
\Deffunc{lua_settagmethod}
\begin{verbatim}
-lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method);
+lua_Object lua_settagmethod (int tag, char *event);
\end{verbatim}
The first parameter is the tag,
-the second is the event name \see{tag-method},
-and the third is a CFunction to be used as the new method.
+the second is the event name \see{tag-method};
+the new method is pushed from C2lua.
This function returns a \verb|lua_Object|,
which is the old tag method value.
To get just the current value of a tag method,
diff --git a/mathlib.c b/mathlib.c
@@ -3,7 +3,7 @@
** Mathematics library to LUA
*/
-char *rcs_mathlib="$Id: mathlib.c,v 1.23 1997/04/06 14:08:08 roberto Exp roberto $";
+char *rcs_mathlib="$Id: mathlib.c,v 1.24 1997/06/09 17:30:10 roberto Exp roberto $";
#include <stdlib.h>
#include <math.h>
@@ -210,7 +210,8 @@ static struct luaL_reg mathlib[] = {
void mathlib_open (void)
{
luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
+ lua_pushcfunction(math_pow);
lua_pushnumber(0); /* to get its tag */
- lua_settagmethod(lua_tag(lua_pop()), "pow", math_pow);
+ lua_settagmethod(lua_tag(lua_pop()), "pow");
}
diff --git a/opcode.c b/opcode.c
@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio
*/
-char *rcs_opcode="$Id: opcode.c,v 4.11 1997/06/16 19:48:18 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 4.12 1997/06/19 17:46:12 roberto Exp roberto $";
#include <setjmp.h>
#include <stdio.h>
@@ -654,21 +654,21 @@ lua_Object lua_gettagmethod (int tag, char *event)
return put_luaObjectonTop();
}
-lua_Object lua_settagmethod (int tag, char *event, lua_CFunction method)
+lua_Object lua_settagmethod (int tag, char *event)
{
+ TObject newmethod;
+ checkCparams(1);
+ newmethod = *(--top);
lua_pushnumber(tag);
lua_pushstring(event);
- if (method)
- lua_pushcfunction (method);
- else
- lua_pushnil();
+ *top = newmethod; incr_top;
do_unprotectedrun(luaI_settagmethod, 3, 1);
return put_luaObjectonTop();
}
-lua_Object lua_seterrormethod (lua_CFunction method)
+lua_Object lua_seterrormethod (void)
{
- lua_pushcfunction(method);
+ checkCparams(1);
do_unprotectedrun(luaI_seterrormethod, 1, 1);
return put_luaObjectonTop();
}