/* ** Function to index a table. Receives the table at top-2 and the index ** at top-1. */ static void pushsubscript (void) { TObject *im; if (ttype(top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */ im = luaI_getimbyObj(top-2, IM_GETTABLE); else { /* object is a table... */ int tg = (top-2)->value.a->htag; im = luaI_getim(tg, IM_GETTABLE); if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ TObject *h = lua_hashget(avalue(top-2), top-1); if (h != NULL && ttype(h) != LUA_T_NIL) { --top; *(top-1) = *h; } else if (ttype(im=luaI_getim(tg, IM_INDEX)) != LUA_T_NIL) callIM(im, 2, 1); else { --top; ttype(top-1) = LUA_T_NIL; } return; } /* else it has a "gettable" method, go through to next command */ } /* object is not a table, or it has a "gettable" method */ if (ttype(im) != LUA_T_NIL) callIM(im, 2, 1); else lua_error("indexed expression not a table"); }
lua_Object lua_rawgettable (void) { checkCparams(2); if (ttype(top-2) != LUA_T_ARRAY) lua_error("indexed expression not a table in raw gettable"); else { TObject *h = lua_hashget(avalue(top-2), top-1); --top; if (h != NULL) *(top-1) = *h; else ttype(top-1) = LUA_T_NIL; } return put_luaObjectonTop(); }
/* ** Function to index a table. Receives the table at top-2 and the index ** at top-1. */ static void pushsubscript (void) { if (tag(top-2) != LUA_T_ARRAY) callFB(FB_GETTABLE); else { Object *h = lua_hashget(avalue(top-2), top-1); if (h == NULL || tag(h) == LUA_T_NIL) callFB(FB_INDEX); else { --top; *(top-1) = *h; } } }