6 char *rcs_fallback
="$Id: fallback.c,v 1.11 1995/02/06 19:34:03 roberto Exp $";
18 static void errorFB (void);
19 static void indexFB (void);
20 static void gettableFB (void);
21 static void arithFB (void);
22 static void concatFB (void);
23 static void orderFB (void);
24 static void GDFB (void);
25 static void funcFB (void);
29 ** Warning: This list must be in the same order as the #define's
31 struct FB luaI_fallBacks
[] = {
32 {"error", {LUA_T_CFUNCTION
, errorFB
}},
33 {"index", {LUA_T_CFUNCTION
, indexFB
}},
34 {"gettable", {LUA_T_CFUNCTION
, gettableFB
}},
35 {"arith", {LUA_T_CFUNCTION
, arithFB
}},
36 {"order", {LUA_T_CFUNCTION
, orderFB
}},
37 {"concat", {LUA_T_CFUNCTION
, concatFB
}},
38 {"settable", {LUA_T_CFUNCTION
, gettableFB
}},
39 {"gc", {LUA_T_CFUNCTION
, GDFB
}},
40 {"function", {LUA_T_CFUNCTION
, funcFB
}}
43 #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB))
45 void luaI_setfallback (void)
48 char *name
= lua_getstring(lua_getparam(1));
49 lua_Object func
= lua_getparam(2);
50 if (name
== NULL
|| !(lua_isfunction(func
) || lua_iscfunction(func
)))
55 for (i
=0; i
<N_FB
; i
++)
57 if (strcmp(luaI_fallBacks
[i
].kind
, name
) == 0)
59 luaI_pushobject(&luaI_fallBacks
[i
].function
);
60 luaI_fallBacks
[i
].function
= *luaI_Address(func
);
69 static void errorFB (void)
71 lua_Object o
= lua_getparam(1);
73 fprintf (stderr
, "lua: %s\n", lua_getstring(o
));
75 fprintf(stderr
, "lua: unknown error\n");
79 static void indexFB (void)
85 static void gettableFB (void)
87 lua_reportbug("indexed expression not a table");
91 static void arithFB (void)
93 lua_reportbug("unexpected type at conversion to number");
96 static void concatFB (void)
98 lua_reportbug("unexpected type at conversion to string");
102 static void orderFB (void)
104 lua_reportbug("unexpected type at comparison");
107 static void GDFB (void) { }
109 static void funcFB (void)
111 lua_reportbug("call expression not a function");
119 static Object
*lockArray
= NULL
;
120 static Word lockSize
= 0;
122 int luaI_lock (Object
*object
)
126 if (tag(object
) == LUA_T_NIL
)
128 for (i
=0; i
<lockSize
; i
++)
129 if (tag(&lockArray
[i
]) == LUA_T_NIL
)
131 lockArray
[i
] = *object
;
134 /* no more empty spaces */
136 if (lockArray
== NULL
)
139 lockArray
= newvector(lockSize
, Object
);
143 lockSize
= 3*oldSize
/2 + 5;
144 lockArray
= growvector(lockArray
, lockSize
, Object
);
146 for (i
=oldSize
; i
<lockSize
; i
++)
147 tag(&lockArray
[i
]) = LUA_T_NIL
;
148 lockArray
[oldSize
] = *object
;
153 void lua_unlock (int ref
)
155 tag(&lockArray
[ref
]) = LUA_T_NIL
;
159 Object
*luaI_getlocked (int ref
)
161 return &lockArray
[ref
];
165 void luaI_travlock (void (*fn
)(Object
*))
168 for (i
=0; i
<lockSize
; i
++)