aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-09-20 11:57:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-09-20 11:57:29 -0300
commit04265655a8cda2d3402c339fc388f0b225c142fb (patch)
tree5439f3216fd9d2738c3343f443d839a0059c1628 /ltm.c
parente10788b2ff735916bbf6b4ba0e040a4568658ca3 (diff)
downloadlua-04265655a8cda2d3402c339fc388f0b225c142fb.tar.gz
lua-04265655a8cda2d3402c339fc388f0b225c142fb.tar.bz2
lua-04265655a8cda2d3402c339fc388f0b225c142fb.zip
compatibility with old fallback system now provided by external module
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c97
1 files changed, 2 insertions, 95 deletions
diff --git a/ltm.c b/ltm.c
index 4c0a0876..f5da877f 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.25 1999/05/21 19:41:49 roberto Exp roberto $ 2** $Id: ltm.c,v 1.26 1999/08/16 20:52:00 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -45,7 +45,7 @@ static const char luaT_validevents[NUM_TAGS][IM_N] = {
45{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ 45{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */
46}; 46};
47 47
48static int luaT_validevent (int t, int e) { /* ORDER LUA_T */ 48int luaT_validevent (int t, int e) { /* ORDER LUA_T */
49 return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e]; 49 return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e];
50} 50}
51 51
@@ -155,96 +155,3 @@ const char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */
155 return NULL; 155 return NULL;
156} 156}
157 157
158
159/*
160* ===================================================================
161* compatibility with old fallback system
162*/
163#ifdef LUA_COMPAT2_5
164
165#include "lapi.h"
166#include "lstring.h"
167
168static void errorFB (void)
169{
170 lua_Object o = lua_getparam(1);
171 if (lua_isstring(o))
172 fprintf(stderr, "lua: %s\n", lua_getstring(o));
173 else
174 fprintf(stderr, "lua: unknown error\n");
175}
176
177
178static void nilFB (void) { }
179
180
181static void typeFB (void) {
182 lua_error("unexpected type");
183}
184
185
186static void fillvalids (IMS e, TObject *func) {
187 int t;
188 for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++)
189 if (luaT_validevent(t, e))
190 *luaT_getim(t, e) = *func;
191}
192
193
194void luaT_setfallback (void) {
195 static const char *const oldnames [] = {"error", "getglobal", "arith",
196 "order", NULL};
197 TObject oldfunc;
198 lua_CFunction replace;
199 const char *name = luaL_check_string(1);
200 lua_Object func = lua_getparam(2);
201 luaL_arg_check(lua_isfunction(func), 2, "function expected");
202 switch (luaL_findstring(name, oldnames)) {
203 case 0: { /* old error fallback */
204 TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
205 oldfunc = *em;
206 *em = *luaA_Address(func);
207 replace = errorFB;
208 break;
209 }
210 case 1: /* old getglobal fallback */
211 oldfunc = *luaT_getim(LUA_T_NIL, IM_GETGLOBAL);
212 *luaT_getim(LUA_T_NIL, IM_GETGLOBAL) = *luaA_Address(func);
213 replace = nilFB;
214 break;
215 case 2: { /* old arith fallback */
216 int i;
217 oldfunc = *luaT_getim(LUA_T_NUMBER, IM_POW);
218 for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
219 fillvalids(i, luaA_Address(func));
220 replace = typeFB;
221 break;
222 }
223 case 3: { /* old order fallback */
224 int i;
225 oldfunc = *luaT_getim(LUA_T_NIL, IM_LT);
226 for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */
227 fillvalids(i, luaA_Address(func));
228 replace = typeFB;
229 break;
230 }
231 default: {
232 int e;
233 if ((e = luaL_findstring(name, luaT_eventname)) >= 0) {
234 oldfunc = *luaT_getim(LUA_T_NIL, e);
235 fillvalids(e, luaA_Address(func));
236 replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
237 }
238 else {
239 luaL_verror("`%.50s' is not a valid fallback name", name);
240 replace = NULL; /* to avoid warnings */
241 }
242 }
243 }
244 if (oldfunc.ttype != LUA_T_NIL)
245 luaA_pushobject(&oldfunc);
246 else
247 lua_pushcfunction(replace);
248}
249#endif
250