diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-04 11:55:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-04 11:55:37 -0300 |
commit | 4321fde2a7059b5d5adcedd4f607f695ea30ff8b (patch) | |
tree | 97d6cf3b89c8e59e659ee4a4cc6165c739d14358 /opcode.c | |
parent | 8f3df1d471d4b7e643492f0e65fac2bdc960398a (diff) | |
download | lua-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.tar.gz lua-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.tar.bz2 lua-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.zip |
error inside an error method could break the stack.
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 35 |
1 files changed, 31 insertions, 4 deletions
@@ -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.15 1997/06/26 21:40:57 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.17 1997/07/03 22:06:06 roberto Exp $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -465,12 +465,39 @@ void lua_travstack (int (*fn)(TObject *)) | |||
465 | ** Error messages and debug functions | 465 | ** Error messages and debug functions |
466 | */ | 466 | */ |
467 | 467 | ||
468 | |||
469 | static void auxerrorim (char *form) | ||
470 | { | ||
471 | lua_Object s = lua_getparam(1); | ||
472 | if (lua_isstring(s)) | ||
473 | fprintf(stderr, form, lua_getstring(s)); | ||
474 | } | ||
475 | |||
476 | |||
477 | static void emergencyerrorf (void) | ||
478 | { | ||
479 | auxerrorim("WARNING - THERE WAS AN ERROR INSIDE AN ERROR METHOD:\n%s\n"); | ||
480 | } | ||
481 | |||
482 | |||
483 | static void stderrorim (void) | ||
484 | { | ||
485 | auxerrorim("lua: %s\n"); | ||
486 | } | ||
487 | |||
488 | |||
489 | TObject luaI_errorim = {LUA_T_CFUNCTION, {stderrorim}}; | ||
490 | |||
491 | |||
468 | static void lua_message (char *s) | 492 | static void lua_message (char *s) |
469 | { | 493 | { |
470 | TObject *im = luaI_geterrorim(); | 494 | TObject im = luaI_errorim; |
471 | if (ttype(im) != LUA_T_NIL) { | 495 | if (ttype(&im) != LUA_T_NIL) { |
496 | luaI_errorim.ttype = LUA_T_CFUNCTION; | ||
497 | luaI_errorim.value.f = emergencyerrorf; | ||
472 | lua_pushstring(s); | 498 | lua_pushstring(s); |
473 | callIM(im, 1, 0); | 499 | callIM(&im, 1, 0); |
500 | luaI_errorim = im; | ||
474 | } | 501 | } |
475 | } | 502 | } |
476 | 503 | ||