From 43382ce5a22838af182807b451a12c474e21da78 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 30 Jan 1996 13:25:23 -0200 Subject: [PATCH] new fallback "getglobal". --- fallback.c | 6 ++++-- fallback.h | 3 ++- opcode.c | 21 +++++++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/fallback.c b/fallback.c index e7f6a8bf..13b763f9 100644 --- a/fallback.c +++ b/fallback.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 1.16 1995/10/17 11:52:38 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 1.17 1995/10/17 14:30:05 roberto Exp roberto $"; #include #include @@ -36,8 +36,10 @@ struct FB luaI_fallBacks[] = { {"concat", {LUA_T_CFUNCTION, {concatFB}}, 2, 1}, {"settable", {LUA_T_CFUNCTION, {gettableFB}}, 3, 0}, {"gc", {LUA_T_CFUNCTION, {GDFB}}, 1, 0}, -{"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1} +{"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1}, /* no fixed number of params or results */ +{"getglobal", {LUA_T_CFUNCTION, {indexFB}}, 1, 1} + /* same default behavior of index FB */ }; #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) diff --git a/fallback.h b/fallback.h index b4ba373b..4ea72808 100644 --- a/fallback.h +++ b/fallback.h @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.9 1995/10/09 13:14:29 roberto Exp roberto $ +** $Id: fallback.h,v 1.10 1995/10/17 11:52:38 roberto Exp roberto $ */ #ifndef fallback_h @@ -23,6 +23,7 @@ extern struct FB { #define FB_SETTABLE 6 #define FB_GC 7 #define FB_FUNCTION 8 +#define FB_GETGLOBAL 9 void luaI_setfallback (void); int luaI_lock (Object *object); diff --git a/opcode.c b/opcode.c index 2708f949..6d2d4cc0 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.52 1996/01/09 20:22:44 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.53 1996/01/23 18:43:07 roberto Exp roberto $"; #include #include @@ -374,6 +374,18 @@ static void storesubscript (void) } +static void getglobal (Word n) +{ + *top = lua_table[n].object; + incr_top; + if (tag(top-1) == LUA_T_NIL) + { /* must call getglobal fallback */ + tag(top-1) = LUA_T_STRING; + tsvalue(top-1) = &lua_table[n].varname->ts; + callFB(FB_GETGLOBAL); + } +} + /* ** Traverse all objects on stack */ @@ -704,10 +716,8 @@ int lua_lock (void) */ lua_Object lua_getglobal (char *name) { - Word n = luaI_findsymbolbyname(name); adjustC(0); - *top = s_object(n); - incr_top; + getglobal(luaI_findsymbolbyname(name)); CBase++; /* incorporate object in the stack */ return Ref(top-1); } @@ -919,8 +929,7 @@ static StkId lua_execute (Byte *pc, StkId base) { CodeWord code; get_word(code,pc); - *top = s_object(code.w); - incr_top; + getglobal(code.w); } break;