new fallback "getglobal".

This commit is contained in:
Roberto Ierusalimschy 1996-01-30 13:25:23 -02:00
parent abfebf1e21
commit 43382ce5a2
3 changed files with 21 additions and 9 deletions

View File

@ -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 <stdio.h>
#include <string.h>
@ -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))

View File

@ -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);

View File

@ -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 <setjmp.h>
#include <stdlib.h>
@ -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;