>>45
not sure why you would want [1] do b instead of C (indexing backwards??) but in case you meant
b instead of a (0-based indexing):
http://www.mediafire.com/?50yzezje052
diff --git a/src/lvm.c b/src/lvm.c
index ee3256a..06d8b14 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -130,6 +130,35 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
luaG_runerror(L, "loop in gettable");
}
+void luaV_gettableX (lua_State *L, const TValue *t, TValue *key, StkId val) {
+ int loop;
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
+ const TValue *tm;
+ if (ttistable(t)) { /* `t' is a table? */
+ Table *h = hvalue(t);
+ const TValue *res;
+ if (ttype(key) == LUA_TNUMBER) {
+ res = luaH_getnum(h, nvalue(key)+1);
+ } else {
+ res = luaH_get(h, key); /* do a primitive get */
+ }
+ if (!ttisnil(res) || /* result is no nil? */
+ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
+ setobj2s(L, val, res);
+ return;
+ }
+ /* else will try the tag method */
+ }
+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
+ luaG_typeerror(L, t, "index");
+ if (ttisfunction(tm)) {
+ callTMres(L, val, tm, t, key);
+ return;
+ }
+ t = tm; /* else repeat with `tm' */
+ }
+ luaG_runerror(L, "loop in gettable");
+}
void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
int loop;
@@ -434,7 +463,7 @@ void luaV_execute (lua_State *L, int nexeccalls) {
continue;
}
case OP_GETTABLE: {
- Protect(luaV_gettable(L, RB(i), RKC(i), ra));
+ Protect(luaV_gettableX(L, RB(i), RKC(i), ra));
continue;
}
case OP_SETGLOBAL: {
diff --git a/src/lvm.h b/src/lvm.h
index bfe4f56..268180f 100644
--- a/src/lvm.h
+++ b/src/lvm.h
@@ -28,6 +28,8 @@ LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
StkId val);
+LUAI_FUNC void luaV_gettableX (lua_State *L, const TValue *t, TValue *key,
+ StkId val);
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
StkId val);
LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);