aboutsummaryrefslogtreecommitdiff
path: root/fallback.c
diff options
context:
space:
mode:
Diffstat (limited to 'fallback.c')
-rw-r--r--fallback.c91
1 files changed, 43 insertions, 48 deletions
diff --git a/fallback.c b/fallback.c
index 25f52773..12c4509d 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.2 1997/04/04 22:24:51 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 2.3 1997/04/06 14:08:08 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -102,18 +102,9 @@ char *luaI_eventname[] = { /* ORDER IM */
102 102
103 103
104 104
105static int findstring (char *name, char *list[])
106{
107 int i;
108 for (i=0; list[i]; i++)
109 if (strcmp(list[i], name) == 0)
110 return i;
111 return -1; /* name not found */
112}
113
114static int luaI_checkevent (char *name, char *list[]) 105static int luaI_checkevent (char *name, char *list[])
115{ 106{
116 int e = findstring(name, list); 107 int e = luaI_findstring(name, list);
117 if (e < 0) 108 if (e < 0)
118 luaL_verror("`%s' is not a valid event name", name); 109 luaL_verror("`%s' is not a valid event name", name);
119 return e; 110 return e;
@@ -197,11 +188,8 @@ void luaI_settag (int tag, TObject *o)
197 case LUA_T_ARRAY: 188 case LUA_T_ARRAY:
198 o->value.a->htag = tag; 189 o->value.a->htag = tag;
199 break; 190 break;
200 case LUA_T_USERDATA:
201 o->value.ts->tag = tag;
202 break;
203 default: 191 default:
204 luaL_verror("cannot change tag of a %s", luaI_typenames[-ttype(o)]); 192 luaL_verror("cannot change the tag of a %s", luaI_typenames[-ttype(o)]);
205 } 193 }
206} 194}
207 195
@@ -318,45 +306,52 @@ static void fillvalids (IMS e, TObject *func)
318 306
319void luaI_setfallback (void) 307void luaI_setfallback (void)
320{ 308{
321 int e; 309 static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL};
322 TObject oldfunc; 310 TObject oldfunc;
323 lua_CFunction replace; 311 lua_CFunction replace;
324 char *name = luaL_check_string(1); 312 char *name = luaL_check_string(1);
325 lua_Object func = lua_getparam(2); 313 lua_Object func = lua_getparam(2);
326 luaI_initfallbacks(); 314 luaI_initfallbacks();
327 luaL_arg_check(lua_isfunction(func), 2, "function expected"); 315 luaL_arg_check(lua_isfunction(func), 2, "function expected");
328 if (strcmp(name, "error") == 0) { /* old error fallback */ 316 switch (luaI_findstring(name, oldnames)) {
329 oldfunc = errorim; 317 case 0: /* old error fallback */
330 errorim = *luaI_Address(func); 318 oldfunc = errorim;
331 replace = errorFB; 319 errorim = *luaI_Address(func);
332 } 320 replace = errorFB;
333 else if (strcmp(name, "getglobal") == 0) { /* old getglobal fallback */ 321 break;
334 oldfunc = luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL]; 322 case 1: /* old getglobal fallback */
335 luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL] = *luaI_Address(func); 323 oldfunc = luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL];
336 replace = nilFB; 324 luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL] = *luaI_Address(func);
337 } 325 replace = nilFB;
338 else if ((e = findstring(name, luaI_eventname)) >= 0) { 326 break;
339 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[e]; 327 case 2: { /* old arith fallback */
340 fillvalids(e, luaI_Address(func)); 328 int i;
341 replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; 329 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_POW];
342 } 330 for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
343 else if (strcmp(name, "arith") == 0) { /* old arith fallback */ 331 fillvalids(i, luaI_Address(func));
344 int i; 332 replace = typeFB;
345 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_POW]; 333 break;
346 for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ 334 }
347 fillvalids(i, luaI_Address(func)); 335 case 3: { /* old order fallback */
348 replace = typeFB; 336 int i;
349 } 337 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_LT];
350 else if (strcmp(name, "order") == 0) { /* old order fallback */ 338 for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */
351 int i; 339 fillvalids(i, luaI_Address(func));
352 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_LT]; 340 replace = typeFB;
353 for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ 341 break;
354 fillvalids(i, luaI_Address(func)); 342 }
355 replace = typeFB; 343 default: {
356 } 344 int e;
357 else { 345 if ((e = luaI_findstring(name, luaI_eventname)) >= 0) {
358 luaL_verror("`%s' is not a valid fallback name", name); 346 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[e];
359 replace = NULL; /* to avoid warnings */ 347 fillvalids(e, luaI_Address(func));
348 replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
349 }
350 else {
351 luaL_verror("`%s' is not a valid fallback name", name);
352 replace = NULL; /* to avoid warnings */
353 }
354 }
360 } 355 }
361 if (oldfunc.ttype != LUA_T_NIL) 356 if (oldfunc.ttype != LUA_T_NIL)
362 luaI_pushobject(&oldfunc); 357 luaI_pushobject(&oldfunc);