diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-30 13:25:23 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-30 13:25:23 -0200 |
commit | 43382ce5a22838af182807b451a12c474e21da78 (patch) | |
tree | 44a6572d07f256494289e8efd6d96e6218950579 | |
parent | abfebf1e2110eb661e146f01ea82836727b3e794 (diff) | |
download | lua-43382ce5a22838af182807b451a12c474e21da78.tar.gz lua-43382ce5a22838af182807b451a12c474e21da78.tar.bz2 lua-43382ce5a22838af182807b451a12c474e21da78.zip |
new fallback "getglobal".
-rw-r--r-- | fallback.c | 6 | ||||
-rw-r--r-- | fallback.h | 3 | ||||
-rw-r--r-- | opcode.c | 21 |
3 files changed, 21 insertions, 9 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.16 1995/10/17 11:52:38 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.17 1995/10/17 14:30:05 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -36,8 +36,10 @@ struct FB luaI_fallBacks[] = { | |||
36 | {"concat", {LUA_T_CFUNCTION, {concatFB}}, 2, 1}, | 36 | {"concat", {LUA_T_CFUNCTION, {concatFB}}, 2, 1}, |
37 | {"settable", {LUA_T_CFUNCTION, {gettableFB}}, 3, 0}, | 37 | {"settable", {LUA_T_CFUNCTION, {gettableFB}}, 3, 0}, |
38 | {"gc", {LUA_T_CFUNCTION, {GDFB}}, 1, 0}, | 38 | {"gc", {LUA_T_CFUNCTION, {GDFB}}, 1, 0}, |
39 | {"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1} | 39 | {"function", {LUA_T_CFUNCTION, {funcFB}}, -1, -1}, |
40 | /* no fixed number of params or results */ | 40 | /* no fixed number of params or results */ |
41 | {"getglobal", {LUA_T_CFUNCTION, {indexFB}}, 1, 1} | ||
42 | /* same default behavior of index FB */ | ||
41 | }; | 43 | }; |
42 | 44 | ||
43 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) | 45 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.9 1995/10/09 13:14:29 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.10 1995/10/17 11:52:38 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -23,6 +23,7 @@ extern struct FB { | |||
23 | #define FB_SETTABLE 6 | 23 | #define FB_SETTABLE 6 |
24 | #define FB_GC 7 | 24 | #define FB_GC 7 |
25 | #define FB_FUNCTION 8 | 25 | #define FB_FUNCTION 8 |
26 | #define FB_GETGLOBAL 9 | ||
26 | 27 | ||
27 | void luaI_setfallback (void); | 28 | void luaI_setfallback (void); |
28 | int luaI_lock (Object *object); | 29 | int luaI_lock (Object *object); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.52 1996/01/09 20:22:44 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.53 1996/01/23 18:43:07 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -374,6 +374,18 @@ static void storesubscript (void) | |||
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | static void getglobal (Word n) | ||
378 | { | ||
379 | *top = lua_table[n].object; | ||
380 | incr_top; | ||
381 | if (tag(top-1) == LUA_T_NIL) | ||
382 | { /* must call getglobal fallback */ | ||
383 | tag(top-1) = LUA_T_STRING; | ||
384 | tsvalue(top-1) = &lua_table[n].varname->ts; | ||
385 | callFB(FB_GETGLOBAL); | ||
386 | } | ||
387 | } | ||
388 | |||
377 | /* | 389 | /* |
378 | ** Traverse all objects on stack | 390 | ** Traverse all objects on stack |
379 | */ | 391 | */ |
@@ -704,10 +716,8 @@ int lua_lock (void) | |||
704 | */ | 716 | */ |
705 | lua_Object lua_getglobal (char *name) | 717 | lua_Object lua_getglobal (char *name) |
706 | { | 718 | { |
707 | Word n = luaI_findsymbolbyname(name); | ||
708 | adjustC(0); | 719 | adjustC(0); |
709 | *top = s_object(n); | 720 | getglobal(luaI_findsymbolbyname(name)); |
710 | incr_top; | ||
711 | CBase++; /* incorporate object in the stack */ | 721 | CBase++; /* incorporate object in the stack */ |
712 | return Ref(top-1); | 722 | return Ref(top-1); |
713 | } | 723 | } |
@@ -919,8 +929,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
919 | { | 929 | { |
920 | CodeWord code; | 930 | CodeWord code; |
921 | get_word(code,pc); | 931 | get_word(code,pc); |
922 | *top = s_object(code.w); | 932 | getglobal(code.w); |
923 | incr_top; | ||
924 | } | 933 | } |
925 | break; | 934 | break; |
926 | 935 | ||