From 4321fde2a7059b5d5adcedd4f607f695ea30ff8b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 4 Jul 1997 11:55:37 -0300 Subject: error inside an error method could break the stack. --- opcode.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'opcode.c') 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; } } -- cgit v1.2.3-55-g6feb