aboutsummaryrefslogtreecommitdiff
path: root/fallback.c
diff options
context:
space:
mode:
Diffstat (limited to 'fallback.c')
-rw-r--r--fallback.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/fallback.c b/fallback.c
index 12c4509d..834e2dcd 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.3 1997/04/06 14:08:08 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 2.4 1997/04/07 14:48:53 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -111,9 +111,7 @@ static int luaI_checkevent (char *name, char *list[])
111} 111}
112 112
113 113
114static struct IM { 114struct IM *luaI_IMtable = NULL;
115 TObject int_method[IM_N];
116} *luaI_IMtable = NULL;
117 115
118static int IMtable_size = 0; 116static int IMtable_size = 0;
119static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ 117static int last_tag = LUA_T_NIL; /* ORDER LUA_T */
@@ -141,7 +139,7 @@ static void init_entry (int tag)
141{ 139{
142 int i; 140 int i;
143 for (i=0; i<IM_N; i++) 141 for (i=0; i<IM_N; i++)
144 luaI_IMtable[-tag].int_method[i].ttype = LUA_T_NIL; 142 ttype(luaI_getim(tag, i)) = LUA_T_NIL;
145} 143}
146 144
147void luaI_initfallbacks (void) 145void luaI_initfallbacks (void)
@@ -194,32 +192,26 @@ void luaI_settag (int tag, TObject *o)
194} 192}
195 193
196 194
197int luaI_tag (TObject *o) 195int luaI_efectivetag (TObject *o)
198{ 196{
199 lua_Type t = ttype(o); 197 lua_Type t = ttype(o);
200 if (t == LUA_T_USERDATA) 198 if (t == LUA_T_USERDATA) {
201 return o->value.ts->tag; 199 int tag = o->value.ts->tag;
200 return (tag >= 0) ? LUA_T_USERDATA : tag;
201 }
202 else if (t == LUA_T_ARRAY) 202 else if (t == LUA_T_ARRAY)
203 return o->value.a->htag; 203 return o->value.a->htag;
204 else return t; 204 else return t;
205} 205}
206 206
207 207
208TObject *luaI_getim (int tag, IMS event)
209{
210 if (tag > LUA_T_USERDATA)
211 tag = LUA_T_USERDATA; /* default for non-registered tags */
212 return &luaI_IMtable[-tag].int_method[event];
213}
214
215
216void luaI_gettagmethod (void) 208void luaI_gettagmethod (void)
217{ 209{
218 int t = (int)luaL_check_number(1); 210 int t = (int)luaL_check_number(1);
219 int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); 211 int e = luaI_checkevent(luaL_check_string(2), luaI_eventname);
220 checktag(t); 212 checktag(t);
221 if (validevent(t, e)) 213 if (validevent(t, e))
222 luaI_pushobject(&luaI_IMtable[-t].int_method[e]); 214 luaI_pushobject(luaI_getim(t,e));
223} 215}
224 216
225 217
@@ -234,8 +226,8 @@ void luaI_settagmethod (void)
234 luaI_eventname[e], t); 226 luaI_eventname[e], t);
235 luaL_arg_check(lua_isnil(func) || lua_isfunction(func), 227 luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
236 3, "function expected"); 228 3, "function expected");
237 luaI_pushobject(&luaI_IMtable[-t].int_method[e]); 229 luaI_pushobject(luaI_getim(t,e));
238 luaI_IMtable[-t].int_method[e] = *luaI_Address(func); 230 *luaI_getim(t, e) = *luaI_Address(func);
239} 231}
240 232
241 233
@@ -264,7 +256,7 @@ char *luaI_travfallbacks (int (*fn)(TObject *))
264 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ 256 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
265 int t; 257 int t;
266 for (t=0; t>=last_tag; t--) 258 for (t=0; t>=last_tag; t--)
267 if (fn(&luaI_IMtable[-t].int_method[e])) 259 if (fn(luaI_getim(t,e)))
268 return luaI_eventname[e]; 260 return luaI_eventname[e];
269 } 261 }
270 return NULL; 262 return NULL;
@@ -301,7 +293,7 @@ static void fillvalids (IMS e, TObject *func)
301 int t; 293 int t;
302 for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) 294 for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++)
303 if (validevent(t, e)) 295 if (validevent(t, e))
304 luaI_IMtable[-t].int_method[e] = *func; 296 *luaI_getim(t, e) = *func;
305} 297}
306 298
307void luaI_setfallback (void) 299void luaI_setfallback (void)
@@ -320,13 +312,13 @@ void luaI_setfallback (void)
320 replace = errorFB; 312 replace = errorFB;
321 break; 313 break;
322 case 1: /* old getglobal fallback */ 314 case 1: /* old getglobal fallback */
323 oldfunc = luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL]; 315 oldfunc = *luaI_getim(LUA_T_NIL, IM_GETGLOBAL);
324 luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL] = *luaI_Address(func); 316 *luaI_getim(LUA_T_NIL, IM_GETGLOBAL) = *luaI_Address(func);
325 replace = nilFB; 317 replace = nilFB;
326 break; 318 break;
327 case 2: { /* old arith fallback */ 319 case 2: { /* old arith fallback */
328 int i; 320 int i;
329 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_POW]; 321 oldfunc = *luaI_getim(LUA_T_USERDATA, IM_POW);
330 for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ 322 for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
331 fillvalids(i, luaI_Address(func)); 323 fillvalids(i, luaI_Address(func));
332 replace = typeFB; 324 replace = typeFB;
@@ -334,7 +326,7 @@ void luaI_setfallback (void)
334 } 326 }
335 case 3: { /* old order fallback */ 327 case 3: { /* old order fallback */
336 int i; 328 int i;
337 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_LT]; 329 oldfunc = *luaI_getim(LUA_T_USERDATA, IM_LT);
338 for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ 330 for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */
339 fillvalids(i, luaI_Address(func)); 331 fillvalids(i, luaI_Address(func));
340 replace = typeFB; 332 replace = typeFB;
@@ -343,7 +335,7 @@ void luaI_setfallback (void)
343 default: { 335 default: {
344 int e; 336 int e;
345 if ((e = luaI_findstring(name, luaI_eventname)) >= 0) { 337 if ((e = luaI_findstring(name, luaI_eventname)) >= 0) {
346 oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[e]; 338 oldfunc = *luaI_getim(LUA_T_USERDATA, e);
347 fillvalids(e, luaI_Address(func)); 339 fillvalids(e, luaI_Address(func));
348 replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; 340 replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
349 } 341 }