mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
compatibility with old fallback system now provided by external module
This commit is contained in:
parent
e10788b2ff
commit
04265655a8
27
lapi.c
27
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
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** 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);
|
luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
|
||||||
L->stack.stack[L->Cstack.base++] = *(--L->stack.top);
|
L->stack.stack[L->Cstack.base++] = *(--L->stack.top);
|
||||||
return L->Cstack.base; /* this is +1 real position (see Ref) */
|
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
|
|
||||||
|
|
||||||
|
3
lapi.h
3
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
|
** Auxiliary functions from Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -18,5 +18,6 @@ void luaA_packresults (void);
|
|||||||
int luaA_passresults (void);
|
int luaA_passresults (void);
|
||||||
TaggedString *luaA_nextvar (TaggedString *g);
|
TaggedString *luaA_nextvar (TaggedString *g);
|
||||||
int luaA_next (const Hash *t, int i);
|
int luaA_next (const Hash *t, int i);
|
||||||
|
lua_Object put_luaObjectonTop (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
12
lbuiltin.c
12
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
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -44,13 +44,14 @@ static void pushtagstring (TaggedString *s) {
|
|||||||
|
|
||||||
static real getsize (const Hash *h) {
|
static real getsize (const Hash *h) {
|
||||||
real max = 0;
|
real max = 0;
|
||||||
int i;
|
int i = nhash(h);
|
||||||
for (i = 0; i<nhash(h); i++) {
|
Node *n = h->node;
|
||||||
Node *n = h->node+i;
|
while (i--) {
|
||||||
if (ttype(ref(n)) == LUA_T_NUMBER &&
|
if (ttype(ref(n)) == LUA_T_NUMBER &&
|
||||||
ttype(val(n)) != LUA_T_NIL &&
|
ttype(val(n)) != LUA_T_NIL &&
|
||||||
nvalue(ref(n)) > max)
|
nvalue(ref(n)) > max)
|
||||||
max = nvalue(ref(n));
|
max = nvalue(ref(n));
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
@ -677,9 +678,6 @@ static void testC (void) {
|
|||||||
|
|
||||||
|
|
||||||
static const struct luaL_reg builtin_funcs[] = {
|
static const struct luaL_reg builtin_funcs[] = {
|
||||||
#ifdef LUA_COMPAT2_5
|
|
||||||
{"setfallback", luaT_setfallback},
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{"testC", testC},
|
{"testC", testC},
|
||||||
{"totalmem", mem_query},
|
{"totalmem", mem_query},
|
||||||
|
97
ltm.c
97
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
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** 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 */
|
{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];
|
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;
|
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
|
|
||||||
|
|
||||||
|
4
ltm.h
4
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
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** 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 TObject *luaT_gettagmethod (int t, const char *event);
|
||||||
const char *luaT_travtagmethods (int (*fn)(TObject *));
|
const char *luaT_travtagmethods (int (*fn)(TObject *));
|
||||||
|
|
||||||
void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
|
int luaT_validevent (int t, int e);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user