commit 04265655a8cda2d3402c339fc388f0b225c142fb
parent e10788b2ff735916bbf6b4ba0e040a4568658ca3
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 20 Sep 1999 11:57:07 -0300
compatibility with old fallback system now provided by external module
Diffstat:
M | lapi.c | | | 27 | ++------------------------- |
M | lapi.h | | | 3 | ++- |
M | lbuiltin.c | | | 12 | +++++------- |
M | ltm.c | | | 97 | ++----------------------------------------------------------------------------- |
M | ltm.h | | | 4 | ++-- |
5 files changed, 13 insertions(+), 130 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.47 1999/06/22 20:37:23 roberto Exp roberto $
+** $Id: lapi.c,v 1.48 1999/08/16 20:52:00 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -85,7 +85,7 @@ static lua_Object put_luaObject (const TObject *o) {
}
-static lua_Object put_luaObjectonTop (void) {
+lua_Object put_luaObjectonTop (void) {
luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
L->stack.stack[L->Cstack.base++] = *(--L->stack.top);
return L->Cstack.base; /* this is +1 real position (see Ref) */
@@ -629,26 +629,3 @@ lua_Object lua_getref (int ref) {
/* }====================================================== */
-
-
-#ifdef LUA_COMPAT2_5
-/*
-** API: set a function as a fallback
-*/
-
-static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) {
- luaD_openstack(nParams);
- (L->stack.top-nParams)->ttype = LUA_T_CPROTO;
- (L->stack.top-nParams)->value.f = f;
- luaD_calln(nParams, nResults);
-}
-
-
-lua_Object lua_setfallback (char *name, lua_CFunction fallback) {
- lua_pushstring(name);
- lua_pushcfunction(fallback);
- do_unprotectedrun(luaT_setfallback, 2, 1);
- return put_luaObjectonTop();
-}
-#endif
-
diff --git a/lapi.h b/lapi.h
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.h,v 1.4 1999/02/23 14:57:28 roberto Exp roberto $
+** $Id: lapi.h,v 1.5 1999/08/16 20:52:00 roberto Exp roberto $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@@ -18,5 +18,6 @@ void luaA_packresults (void);
int luaA_passresults (void);
TaggedString *luaA_nextvar (TaggedString *g);
int luaA_next (const Hash *t, int i);
+lua_Object put_luaObjectonTop (void);
#endif
diff --git a/lbuiltin.c b/lbuiltin.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbuiltin.c,v 1.61 1999/08/16 20:52:00 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.62 1999/09/08 20:45:18 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@@ -44,13 +44,14 @@ static void pushtagstring (TaggedString *s) {
static real getsize (const Hash *h) {
real max = 0;
- int i;
- for (i = 0; i<nhash(h); i++) {
- Node *n = h->node+i;
+ int i = nhash(h);
+ Node *n = h->node;
+ while (i--) {
if (ttype(ref(n)) == LUA_T_NUMBER &&
ttype(val(n)) != LUA_T_NIL &&
nvalue(ref(n)) > max)
max = nvalue(ref(n));
+ n++;
}
return max;
}
@@ -677,9 +678,6 @@ static void testC (void) {
static const struct luaL_reg builtin_funcs[] = {
-#ifdef LUA_COMPAT2_5
- {"setfallback", luaT_setfallback},
-#endif
#ifdef DEBUG
{"testC", testC},
{"totalmem", mem_query},
diff --git a/ltm.c b/ltm.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltm.c,v 1.25 1999/05/21 19:41:49 roberto Exp roberto $
+** $Id: ltm.c,v 1.26 1999/08/16 20:52:00 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -45,7 +45,7 @@ static const char luaT_validevents[NUM_TAGS][IM_N] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */
};
-static int luaT_validevent (int t, int e) { /* ORDER LUA_T */
+int luaT_validevent (int t, int e) { /* ORDER LUA_T */
return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e];
}
@@ -155,96 +155,3 @@ const char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */
return NULL;
}
-
-/*
-* ===================================================================
-* compatibility with old fallback system
-*/
-#ifdef LUA_COMPAT2_5
-
-#include "lapi.h"
-#include "lstring.h"
-
-static void errorFB (void)
-{
- lua_Object o = lua_getparam(1);
- if (lua_isstring(o))
- fprintf(stderr, "lua: %s\n", lua_getstring(o));
- else
- fprintf(stderr, "lua: unknown error\n");
-}
-
-
-static void nilFB (void) { }
-
-
-static void typeFB (void) {
- lua_error("unexpected type");
-}
-
-
-static void fillvalids (IMS e, TObject *func) {
- int t;
- for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++)
- if (luaT_validevent(t, e))
- *luaT_getim(t, e) = *func;
-}
-
-
-void luaT_setfallback (void) {
- static const char *const oldnames [] = {"error", "getglobal", "arith",
- "order", NULL};
- TObject oldfunc;
- lua_CFunction replace;
- const char *name = luaL_check_string(1);
- lua_Object func = lua_getparam(2);
- luaL_arg_check(lua_isfunction(func), 2, "function expected");
- switch (luaL_findstring(name, oldnames)) {
- case 0: { /* old error fallback */
- TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
- oldfunc = *em;
- *em = *luaA_Address(func);
- replace = errorFB;
- break;
- }
- case 1: /* old getglobal fallback */
- oldfunc = *luaT_getim(LUA_T_NIL, IM_GETGLOBAL);
- *luaT_getim(LUA_T_NIL, IM_GETGLOBAL) = *luaA_Address(func);
- replace = nilFB;
- break;
- case 2: { /* old arith fallback */
- int i;
- oldfunc = *luaT_getim(LUA_T_NUMBER, IM_POW);
- for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
- fillvalids(i, luaA_Address(func));
- replace = typeFB;
- break;
- }
- case 3: { /* old order fallback */
- int i;
- oldfunc = *luaT_getim(LUA_T_NIL, IM_LT);
- for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */
- fillvalids(i, luaA_Address(func));
- replace = typeFB;
- break;
- }
- default: {
- int e;
- if ((e = luaL_findstring(name, luaT_eventname)) >= 0) {
- oldfunc = *luaT_getim(LUA_T_NIL, e);
- fillvalids(e, luaA_Address(func));
- replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;
- }
- else {
- luaL_verror("`%.50s' is not a valid fallback name", name);
- replace = NULL; /* to avoid warnings */
- }
- }
- }
- if (oldfunc.ttype != LUA_T_NIL)
- luaA_pushobject(&oldfunc);
- else
- lua_pushcfunction(replace);
-}
-#endif
-
diff --git a/ltm.h b/ltm.h
@@ -1,5 +1,5 @@
/*
-** $Id: ltm.h,v 1.5 1999/01/15 13:11:57 roberto Exp roberto $
+** $Id: ltm.h,v 1.6 1999/08/16 20:52:00 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -57,6 +57,6 @@ void luaT_settagmethod (int t, const char *event, TObject *func);
const TObject *luaT_gettagmethod (int t, const char *event);
const char *luaT_travtagmethods (int (*fn)(TObject *));
-void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
+int luaT_validevent (int t, int e);
#endif