new interface to "lua_seterrormethod" and "lua_settagmethod", to

allow the use of Lua functions too.
This commit is contained in:
Roberto Ierusalimschy 1997-06-19 15:03:04 -03:00
parent a38f093f05
commit 88f020b626
5 changed files with 25 additions and 22 deletions

View File

@ -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();
}

6
lua.h
View File

@ -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 */

View File

@ -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,

View File

@ -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");
}

View File

@ -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();
}