lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 9deac27704eee47f858f6b41a386c3198bc49587
parent d531ccd082a73aa2fda585dfe5edf2749c7e7d13
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 10 Nov 1994 15:11:33 -0200

fallback list moved from opcode.c to fallback.c

Diffstat:
Mfallback.c | 42+++++++++++++++++++++++++++++++++++++++++-
Mfallback.h | 17++++++++++++++++-
Mopcode.c | 74+++++++++++---------------------------------------------------------------
Mopcode.h | 3+--
4 files changed, 69 insertions(+), 67 deletions(-)

diff --git a/fallback.c b/fallback.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $"; #include <stdio.h> #include <stdlib.h> @@ -14,6 +14,46 @@ char *rcs_fallback="$Id: fallback.c,v 1.2 1994/11/08 19:56:39 roberto Exp robert #include "lua.h" +/* +** Warning: This list must be in the same order as the #define's +*/ +struct FB luaI_fallBacks[] = { +{"error", {LUA_T_CFUNCTION, luaI_errorFB}}, +{"index", {LUA_T_CFUNCTION, luaI_indexFB}}, +{"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, +{"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, +{"order", {LUA_T_CFUNCTION, luaI_orderFB}}, +{"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, +{"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, +{"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} +}; + +#define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) + +void luaI_setfallback (void) +{ + int i; + char *name = lua_getstring(lua_getparam(1)); + lua_Object func = lua_getparam(2); + if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func))) + { + lua_pushnil(); + return; + } + for (i=0; i<N_FB; i++) + { + if (strcmp(luaI_fallBacks[i].kind, name) == 0) + { + luaI_pushobject(&luaI_fallBacks[i].function); + luaI_fallBacks[i].function = *luaI_Address(func); + return; + } + } + /* name not found */ + lua_pushnil(); +} + + void luaI_errorFB (void) { lua_Object o = lua_getparam(1); diff --git a/fallback.h b/fallback.h @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.1 1994/11/07 15:20:56 roberto Exp roberto $ +** $Id: fallback.h,v 1.2 1994/11/08 19:56:39 roberto Exp roberto $ */ #ifndef fallback_h @@ -7,6 +7,21 @@ #include "opcode.h" +extern struct FB { + char *kind; + Object function; +} luaI_fallBacks[]; + +#define FB_ERROR 0 +#define FB_INDEX 1 +#define FB_GETTABLE 2 +#define FB_ARITH 3 +#define FB_ORDER 4 +#define FB_CONCAT 5 +#define FB_UNMINUS 6 +#define FB_SETTABLE 7 + +void luaI_setfallback (void); void luaI_errorFB (void); void luaI_indexFB (void); void luaI_gettableFB (void); diff --git a/opcode.c b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.6 1994/11/08 19:56:39 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.7 1994/11/09 18:13:29 roberto Exp roberto $"; #include <stdio.h> #include <stdlib.h> @@ -50,6 +50,7 @@ static int lua_execute (Byte *pc, int base); static void do_call (Object *func, int base, int nResults, int whereRes); + Object *luaI_Address (lua_Object o) { return Address(o); @@ -57,66 +58,13 @@ Object *luaI_Address (lua_Object o) /* -** Fallbacks -*/ - -static struct FB { - char *kind; - Object function; -} fallBacks[] = { -#define FB_ERROR 0 -{"error", {LUA_T_CFUNCTION, luaI_errorFB}}, -#define FB_INDEX 1 -{"index", {LUA_T_CFUNCTION, luaI_indexFB}}, -#define FB_GETTABLE 2 -{"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, -#define FB_ARITH 3 -{"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, -#define FB_ORDER 4 -{"order", {LUA_T_CFUNCTION, luaI_orderFB}}, -#define FB_CONCAT 5 -{"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, -#define FB_UNMINUS 6 -{"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, -#define FB_SETTABLE 7 -{"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} -}; - -#define N_FB (sizeof(fallBacks)/sizeof(struct FB)) - - -void luaI_setfallback (void) -{ - int i; - char *name = lua_getstring(lua_getparam(1)); - lua_Object func = lua_getparam(2); - if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func))) - { - lua_pushnil(); - return; - } - for (i=0; i<N_FB; i++) - { - if (strcmp(fallBacks[i].kind, name) == 0) - { - luaI_pushobject(&fallBacks[i].function); - fallBacks[i].function = *Address(func); - return; - } - } - /* name not found */ - lua_pushnil(); -} - - -/* ** Error messages */ static void lua_message (char *s) { lua_pushstring(s); - do_call(&fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1); + do_call(&luaI_fallBacks[FB_ERROR].function, (top-stack)-1, 0, (top-stack)-1); } /* @@ -311,12 +259,12 @@ static void do_call (Object *func, int base, int nResults, int whereRes) static void pushsubscript (void) { if (tag(top-2) != LUA_T_ARRAY) - do_call(&fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2); + do_call(&luaI_fallBacks[FB_GETTABLE].function, (top-stack)-2, 1, (top-stack)-2); else { Object *h = lua_hashget(avalue(top-2), top-1); if (h == NULL) - do_call(&fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2); + do_call(&luaI_fallBacks[FB_INDEX].function, (top-stack)-2, 1, (top-stack)-2); else { --top; @@ -332,7 +280,7 @@ static void pushsubscript (void) static void storesubscript (void) { if (tag(top-3) != LUA_T_ARRAY) - do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); + do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); else { Object *h = lua_hashdefine (avalue(top-3), top-2); @@ -688,7 +636,7 @@ int lua_type (lua_Object o) static void call_arith (char *op) { lua_pushstring(op); - do_call(&fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3); + do_call(&luaI_fallBacks[FB_ARITH].function, (top-stack)-3, 1, (top-stack)-3); } static void comparison (lua_Type tag_less, lua_Type tag_equal, @@ -702,7 +650,7 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, else if (tostring(l) || tostring(r)) { lua_pushstring(op); - do_call(&fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3); + do_call(&luaI_fallBacks[FB_ORDER].function, (top-stack)-3, 1, (top-stack)-3); return; } else @@ -824,7 +772,7 @@ static int lua_execute (Byte *pc, int base) *(top) = *(top-2-n); *(top-1) = *(top-3-n); top += 2; - do_call(&fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); + do_call(&luaI_fallBacks[FB_SETTABLE].function, (top-stack)-3, 0, (top-stack)-3); } else { @@ -1016,7 +964,7 @@ static int lua_execute (Byte *pc, int base) Object *l = top-2; Object *r = top-1; if (tostring(r) || tostring(l)) - do_call(&fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2); + do_call(&luaI_fallBacks[FB_CONCAT].function, (top-stack)-2, 1, (top-stack)-2); else { svalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r))); @@ -1027,7 +975,7 @@ static int lua_execute (Byte *pc, int base) case MINUSOP: if (tonumber(top-1)) - do_call(&fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1); + do_call(&luaI_fallBacks[FB_UNMINUS].function, (top-stack)-1, 1, (top-stack)-1); else nvalue(top-1) = - nvalue(top-1); break; diff --git a/opcode.h b/opcode.h @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.5 1994/11/07 16:34:44 roberto Exp roberto $ +** $Id: opcode.h,v 3.6 1994/11/09 18:10:58 roberto Exp roberto $ */ #ifndef opcode_h @@ -160,7 +160,6 @@ char *lua_lasttext (void); /* from "lex.c" module */ int yylex (void); /* from "lex.c" module */ void lua_parse (Byte **code); /* from "lua.stx" module */ void lua_travstack (void (*fn)(Object *)); -void luaI_setfallback (void); Object *luaI_Address (lua_Object o); void luaI_pushobject (Object *o);