aboutsummaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-26 11:23:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-26 11:23:55 -0300
commitb546a042e8120adf572aa80e5b2b48c1a19ca0fa (patch)
tree2d32308f154bd3313996b019529a83bb927b2be0 /opcode.c
parentbd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45 (diff)
downloadlua-b546a042e8120adf572aa80e5b2b48c1a19ca0fa.tar.gz
lua-b546a042e8120adf572aa80e5b2b48c1a19ca0fa.tar.bz2
lua-b546a042e8120adf572aa80e5b2b48c1a19ca0fa.zip
another (better?) implementation for "pushsubscript".
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/opcode.c b/opcode.c
index 066e9c05..6fa23a96 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.3 1997/04/15 17:32:47 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.4 1997/04/24 22:59:57 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -320,9 +320,13 @@ static void do_call (StkId base, int nResults)
320*/ 320*/
321static void pushsubscript (void) 321static void pushsubscript (void)
322{ 322{
323 int tg = luaI_efectivetag(top-2); 323 TObject *im;
324 TObject *im = luaI_getim(tg, IM_GETTABLE); 324 if (ttype(top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
325 if (ttype(top-2) == LUA_T_ARRAY && ttype(im) == LUA_T_NIL) { 325 im = luaI_getimbyObj(top-2, IM_GETTABLE);
326 else { /* object is a table... */
327 int tg = (top-2)->value.a->htag;
328 im = luaI_getim(tg, IM_GETTABLE);
329 if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */
326 TObject *h = lua_hashget(avalue(top-2), top-1); 330 TObject *h = lua_hashget(avalue(top-2), top-1);
327 if (h != NULL && ttype(h) != LUA_T_NIL) { 331 if (h != NULL && ttype(h) != LUA_T_NIL) {
328 --top; 332 --top;
@@ -334,13 +338,15 @@ static void pushsubscript (void)
334 --top; 338 --top;
335 ttype(top-1) = LUA_T_NIL; 339 ttype(top-1) = LUA_T_NIL;
336 } 340 }
341 return;
342 }
343 /* else it has a "gettable" method, go through to next command */
337 } 344 }
338 else { /* object is not a table, and/or has a specific "gettable" method */ 345 /* object is not a table, or it has a "gettable" method */
339 if (ttype(im) != LUA_T_NIL) 346 if (ttype(im) != LUA_T_NIL)
340 callIM(im, 2, 1); 347 callIM(im, 2, 1);
341 else 348 else
342 lua_error("indexed expression not a table"); 349 lua_error("indexed expression not a table");
343 }
344} 350}
345 351
346 352