aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fallback.c27
-rw-r--r--fallback.h3
-rw-r--r--opcode.c35
-rw-r--r--opcode.h4
4 files changed, 41 insertions, 28 deletions
diff --git a/fallback.c b/fallback.c
index da7ed923..edec9184 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 2.8 1997/06/17 17:27:07 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 2.10 1997/07/03 22:06:06 roberto Exp $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -238,34 +238,19 @@ void luaI_settagmethod (void)
238} 238}
239 239
240 240
241static void stderrorim (void)
242{
243 lua_Object s = lua_getparam(1);
244 if (lua_isstring(s))
245 fprintf(stderr, "lua: %s\n", lua_getstring(s));
246}
247
248static TObject errorim = {LUA_T_CFUNCTION, {stderrorim}};
249
250
251TObject *luaI_geterrorim (void)
252{
253 return &errorim;
254}
255
256void luaI_seterrormethod (void) 241void luaI_seterrormethod (void)
257{ 242{
258 lua_Object func = lua_getparam(1); 243 lua_Object func = lua_getparam(1);
259 luaL_arg_check(lua_isnil(func) || lua_isfunction(func), 244 luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
260 1, "function expected"); 245 1, "function expected");
261 luaI_pushobject(&errorim); 246 luaI_pushobject(&luaI_errorim);
262 errorim = *luaI_Address(func); 247 luaI_errorim = *luaI_Address(func);
263} 248}
264 249
265char *luaI_travfallbacks (int (*fn)(TObject *)) 250char *luaI_travfallbacks (int (*fn)(TObject *))
266{ 251{
267 int e; 252 int e;
268 if (fn(&errorim)) 253 if (fn(&luaI_errorim))
269 return "error"; 254 return "error";
270 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ 255 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
271 int t; 256 int t;
@@ -322,8 +307,8 @@ void luaI_setfallback (void)
322 luaL_arg_check(lua_isfunction(func), 2, "function expected"); 307 luaL_arg_check(lua_isfunction(func), 2, "function expected");
323 switch (luaI_findstring(name, oldnames)) { 308 switch (luaI_findstring(name, oldnames)) {
324 case 0: /* old error fallback */ 309 case 0: /* old error fallback */
325 oldfunc = errorim; 310 oldfunc = luaI_errorim;
326 errorim = *luaI_Address(func); 311 luaI_errorim = *luaI_Address(func);
327 replace = errorFB; 312 replace = errorFB;
328 break; 313 break;
329 case 1: /* old getglobal fallback */ 314 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 @@
1/* 1/*
2** $Id: fallback.h,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $ 2** $Id: fallback.h,v 1.24 1997/07/03 22:06:06 roberto Exp $
3*/ 3*/
4 4
5#ifndef fallback_h 5#ifndef fallback_h
@@ -54,7 +54,6 @@ char *luaI_travfallbacks (int (*fn)(TObject *));
54 54
55void luaI_settag (int tag, TObject *o); 55void luaI_settag (int tag, TObject *o);
56void luaI_realtag (int tag); 56void luaI_realtag (int tag);
57TObject *luaI_geterrorim (void);
58int luaI_efectivetag (TObject *o); 57int luaI_efectivetag (TObject *o);
59void luaI_settagmethod (void); 58void luaI_settagmethod (void);
60void luaI_gettagmethod (void); 59void 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 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $"; 6char *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
469static 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
477static void emergencyerrorf (void)
478{
479 auxerrorim("WARNING - THERE WAS AN ERROR INSIDE AN ERROR METHOD:\n%s\n");
480}
481
482
483static void stderrorim (void)
484{
485 auxerrorim("lua: %s\n");
486}
487
488
489TObject luaI_errorim = {LUA_T_CFUNCTION, {stderrorim}};
490
491
468static void lua_message (char *s) 492static 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
diff --git a/opcode.h b/opcode.h
index d4516e86..111d3a4d 100644
--- a/opcode.h
+++ b/opcode.h
@@ -1,6 +1,6 @@
1/* 1/*
2** TeCGraf - PUC-Rio 2** TeCGraf - PUC-Rio
3** $Id: opcode.h,v 3.33 1997/04/11 21:34:53 roberto Exp roberto $ 3** $Id: opcode.h,v 3.35 1997/07/03 22:06:06 roberto Exp $
4*/ 4*/
5 5
6#ifndef opcode_h 6#ifndef opcode_h
@@ -168,4 +168,6 @@ void luaI_gcIM (TObject *o);
168int luaI_dorun (TFunc *tf); 168int luaI_dorun (TFunc *tf);
169int lua_domain (void); 169int lua_domain (void);
170 170
171extern TObject luaI_errorim;
172
171#endif 173#endif