aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c27
-rw-r--r--lapi.h3
-rw-r--r--lbuiltin.c12
-rw-r--r--ltm.c97
-rw-r--r--ltm.h4
5 files changed, 13 insertions, 130 deletions
diff --git a/lapi.c b/lapi.c
index dbeb4f59..bc1b2789 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.47 1999/06/22 20:37:23 roberto Exp roberto $ 2** $Id: lapi.c,v 1.48 1999/08/16 20:52:00 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -85,7 +85,7 @@ static lua_Object put_luaObject (const TObject *o) {
85} 85}
86 86
87 87
88static lua_Object put_luaObjectonTop (void) { 88lua_Object put_luaObjectonTop (void) {
89 luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); 89 luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
90 L->stack.stack[L->Cstack.base++] = *(--L->stack.top); 90 L->stack.stack[L->Cstack.base++] = *(--L->stack.top);
91 return L->Cstack.base; /* this is +1 real position (see Ref) */ 91 return L->Cstack.base; /* this is +1 real position (see Ref) */
@@ -629,26 +629,3 @@ lua_Object lua_getref (int ref) {
629 629
630/* }====================================================== */ 630/* }====================================================== */
631 631
632
633
634#ifdef LUA_COMPAT2_5
635/*
636** API: set a function as a fallback
637*/
638
639static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) {
640 luaD_openstack(nParams);
641 (L->stack.top-nParams)->ttype = LUA_T_CPROTO;
642 (L->stack.top-nParams)->value.f = f;
643 luaD_calln(nParams, nResults);
644}
645
646
647lua_Object lua_setfallback (char *name, lua_CFunction fallback) {
648 lua_pushstring(name);
649 lua_pushcfunction(fallback);
650 do_unprotectedrun(luaT_setfallback, 2, 1);
651 return put_luaObjectonTop();
652}
653#endif
654
diff --git a/lapi.h b/lapi.h
index b836f905..38947019 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 1.4 1999/02/23 14:57:28 roberto Exp roberto $ 2** $Id: lapi.h,v 1.5 1999/08/16 20:52:00 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,5 +18,6 @@ void luaA_packresults (void);
18int luaA_passresults (void); 18int luaA_passresults (void);
19TaggedString *luaA_nextvar (TaggedString *g); 19TaggedString *luaA_nextvar (TaggedString *g);
20int luaA_next (const Hash *t, int i); 20int luaA_next (const Hash *t, int i);
21lua_Object put_luaObjectonTop (void);
21 22
22#endif 23#endif
diff --git a/lbuiltin.c b/lbuiltin.c
index b7365f66..74e8c6d0 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.61 1999/08/16 20:52:00 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.62 1999/09/08 20:45:18 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -44,13 +44,14 @@ static void pushtagstring (TaggedString *s) {
44 44
45static real getsize (const Hash *h) { 45static real getsize (const Hash *h) {
46 real max = 0; 46 real max = 0;
47 int i; 47 int i = nhash(h);
48 for (i = 0; i<nhash(h); i++) { 48 Node *n = h->node;
49 Node *n = h->node+i; 49 while (i--) {
50 if (ttype(ref(n)) == LUA_T_NUMBER && 50 if (ttype(ref(n)) == LUA_T_NUMBER &&
51 ttype(val(n)) != LUA_T_NIL && 51 ttype(val(n)) != LUA_T_NIL &&
52 nvalue(ref(n)) > max) 52 nvalue(ref(n)) > max)
53 max = nvalue(ref(n)); 53 max = nvalue(ref(n));
54 n++;
54 } 55 }
55 return max; 56 return max;
56} 57}
@@ -677,9 +678,6 @@ static void testC (void) {
677 678
678 679
679static const struct luaL_reg builtin_funcs[] = { 680static const struct luaL_reg builtin_funcs[] = {
680#ifdef LUA_COMPAT2_5
681 {"setfallback", luaT_setfallback},
682#endif
683#ifdef DEBUG 681#ifdef DEBUG
684 {"testC", testC}, 682 {"testC", testC},
685 {"totalmem", mem_query}, 683 {"totalmem", mem_query},
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
diff --git a/ltm.h b/ltm.h
index 3eaea82e..dda28a5a 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.5 1999/01/15 13:11:57 roberto Exp roberto $ 2** $Id: ltm.h,v 1.6 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*/
@@ -57,6 +57,6 @@ void luaT_settagmethod (int t, const char *event, TObject *func);
57const TObject *luaT_gettagmethod (int t, const char *event); 57const TObject *luaT_gettagmethod (int t, const char *event);
58const char *luaT_travtagmethods (int (*fn)(TObject *)); 58const char *luaT_travtagmethods (int (*fn)(TObject *));
59 59
60void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ 60int luaT_validevent (int t, int e);
61 61
62#endif 62#endif