diff options
| -rw-r--r-- | lapi.c | 27 | ||||
| -rw-r--r-- | lapi.h | 3 | ||||
| -rw-r--r-- | lbuiltin.c | 12 | ||||
| -rw-r--r-- | ltm.c | 97 | ||||
| -rw-r--r-- | ltm.h | 4 |
5 files changed, 13 insertions, 130 deletions
| @@ -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 | ||
| 88 | static lua_Object put_luaObjectonTop (void) { | 88 | lua_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 | |||
| 639 | static 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 | |||
| 647 | lua_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 | |||
| @@ -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); | |||
| 18 | int luaA_passresults (void); | 18 | int luaA_passresults (void); |
| 19 | TaggedString *luaA_nextvar (TaggedString *g); | 19 | TaggedString *luaA_nextvar (TaggedString *g); |
| 20 | int luaA_next (const Hash *t, int i); | 20 | int luaA_next (const Hash *t, int i); |
| 21 | lua_Object put_luaObjectonTop (void); | ||
| 21 | 22 | ||
| 22 | #endif | 23 | #endif |
| @@ -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 | ||
| 45 | static real getsize (const Hash *h) { | 45 | static 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 | ||
| 679 | static const struct luaL_reg builtin_funcs[] = { | 680 | static 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}, |
| @@ -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 | ||
| 48 | static int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | 48 | int 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 | |||
| 168 | static 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 | |||
| 178 | static void nilFB (void) { } | ||
| 179 | |||
| 180 | |||
| 181 | static void typeFB (void) { | ||
| 182 | lua_error("unexpected type"); | ||
| 183 | } | ||
| 184 | |||
| 185 | |||
| 186 | static 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 | |||
| 194 | void 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 | |||
| @@ -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); | |||
| 57 | const TObject *luaT_gettagmethod (int t, const char *event); | 57 | const TObject *luaT_gettagmethod (int t, const char *event); |
| 58 | const char *luaT_travtagmethods (int (*fn)(TObject *)); | 58 | const char *luaT_travtagmethods (int (*fn)(TObject *)); |
| 59 | 59 | ||
| 60 | void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ | 60 | int luaT_validevent (int t, int e); |
| 61 | 61 | ||
| 62 | #endif | 62 | #endif |
