diff --git a/fallback.c b/fallback.c index da7ed923..edec9184 100644 --- a/fallback.c +++ b/fallback.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 2.8 1997/06/17 17:27:07 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 2.10 1997/07/03 22:06:06 roberto Exp $"; #include #include @@ -238,34 +238,19 @@ void luaI_settagmethod (void) } -static void stderrorim (void) -{ - lua_Object s = lua_getparam(1); - if (lua_isstring(s)) - fprintf(stderr, "lua: %s\n", lua_getstring(s)); -} - -static TObject errorim = {LUA_T_CFUNCTION, {stderrorim}}; - - -TObject *luaI_geterrorim (void) -{ - return &errorim; -} - void luaI_seterrormethod (void) { lua_Object func = lua_getparam(1); luaL_arg_check(lua_isnil(func) || lua_isfunction(func), 1, "function expected"); - luaI_pushobject(&errorim); - errorim = *luaI_Address(func); + luaI_pushobject(&luaI_errorim); + luaI_errorim = *luaI_Address(func); } char *luaI_travfallbacks (int (*fn)(TObject *)) { int e; - if (fn(&errorim)) + if (fn(&luaI_errorim)) return "error"; for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ int t; @@ -322,8 +307,8 @@ void luaI_setfallback (void) luaL_arg_check(lua_isfunction(func), 2, "function expected"); switch (luaI_findstring(name, oldnames)) { case 0: /* old error fallback */ - oldfunc = errorim; - errorim = *luaI_Address(func); + oldfunc = luaI_errorim; + luaI_errorim = *luaI_Address(func); replace = errorFB; break; case 1: /* old getglobal fallback */ diff --git a/fallback.h b/fallback.h index 12c82702..1e2ecc56 100644 --- a/fallback.h +++ b/fallback.h @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $ +** $Id: fallback.h,v 1.24 1997/07/03 22:06:06 roberto Exp $ */ #ifndef fallback_h @@ -54,7 +54,6 @@ char *luaI_travfallbacks (int (*fn)(TObject *)); void luaI_settag (int tag, TObject *o); void luaI_realtag (int tag); -TObject *luaI_geterrorim (void); int luaI_efectivetag (TObject *o); void luaI_settagmethod (void); void luaI_gettagmethod (void); diff --git a/opcode.c b/opcode.c index 062c376d..82f63c66 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 4.17 1997/07/03 22:06:06 roberto Exp $"; #include #include @@ -465,12 +465,39 @@ void lua_travstack (int (*fn)(TObject *)) ** Error messages and debug functions */ + +static void auxerrorim (char *form) +{ + lua_Object s = lua_getparam(1); + if (lua_isstring(s)) + fprintf(stderr, form, lua_getstring(s)); +} + + +static void emergencyerrorf (void) +{ + auxerrorim("WARNING - THERE WAS AN ERROR INSIDE AN ERROR METHOD:\n%s\n"); +} + + +static void stderrorim (void) +{ + auxerrorim("lua: %s\n"); +} + + +TObject luaI_errorim = {LUA_T_CFUNCTION, {stderrorim}}; + + static void lua_message (char *s) { - TObject *im = luaI_geterrorim(); - if (ttype(im) != LUA_T_NIL) { + TObject im = luaI_errorim; + if (ttype(&im) != LUA_T_NIL) { + luaI_errorim.ttype = LUA_T_CFUNCTION; + luaI_errorim.value.f = emergencyerrorf; lua_pushstring(s); - callIM(im, 1, 0); + callIM(&im, 1, 0); + luaI_errorim = im; } } diff --git a/opcode.h b/opcode.h index d4516e86..111d3a4d 100644 --- a/opcode.h +++ b/opcode.h @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.33 1997/04/11 21:34:53 roberto Exp roberto $ +** $Id: opcode.h,v 3.35 1997/07/03 22:06:06 roberto Exp $ */ #ifndef opcode_h @@ -168,4 +168,6 @@ void luaI_gcIM (TObject *o); int luaI_dorun (TFunc *tf); int lua_domain (void); +extern TObject luaI_errorim; + #endif