diff --git a/lbaselib.c b/lbaselib.c index ea50cd9c..358ca427 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.171 2005/03/16 16:58:41 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.172 2005/03/22 16:04:29 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -240,7 +240,7 @@ static int luaB_ipairs (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ lua_pushvalue(L, 1); /* state, */ - lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ + lua_pushinteger(L, 0); /* and initial value */ return 3; } @@ -340,12 +340,12 @@ static int luaB_getn (lua_State *L) { static int luaB_unpack (lua_State *L) { - int i = luaL_optint(L, 2, LUA_FIRSTINDEX); + int i = luaL_optint(L, 2, 1); int e = luaL_optint(L, 3, -1); int n; luaL_checktype(L, 1, LUA_TTABLE); if (e == -1) - e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; + e = luaL_getn(L, 1); n = e - i + 1; /* number of elements */ if (n <= 0) return 0; /* empty range */ luaL_checkstack(L, n, "table too big to unpack"); diff --git a/ldo.c b/ldo.c index 8e241e8d..23c0d7a3 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.18 2005/03/16 20:02:48 roberto Exp roberto $ +** $Id: ldo.c,v 2.19 2005/03/18 18:55:09 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -202,7 +202,7 @@ static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, luaC_checkGC(L); htab = luaH_new(L, nvar, 1); /* create `arg' table */ for (i=0; itop - nvar + i); + setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); /* store counter in field `n' */ setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast(lua_Number, nvar)); diff --git a/ltablib.c b/ltablib.c index 42575685..30220300 100644 --- a/ltablib.c +++ b/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp roberto $ +** $Id: ltablib.c,v 1.28 2005/03/16 16:58:41 roberto Exp roberto $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -23,7 +23,7 @@ static int foreachi (lua_State *L) { int i; int n = aux_getn(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); - for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { + for (i=1; i <= n; i++) { lua_pushvalue(L, 2); /* function */ lua_pushinteger(L, i); /* 1st argument */ lua_rawgeti(L, 1, i); /* 2nd argument */ @@ -73,7 +73,7 @@ static int setn (lua_State *L) { static int tinsert (lua_State *L) { - int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ + int e = aux_getn(L, 1) + 1; /* first empty element */ int pos; /* where to insert new element */ if (lua_isnone(L, 3)) /* called with only 2 arguments */ pos = e; /* insert new element at the end */ @@ -87,17 +87,17 @@ static int tinsert (lua_State *L) { lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ } } - luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */ + luaL_setn(L, 1, e); /* new size */ lua_rawseti(L, 1, pos); /* t[pos] = v */ return 0; } static int tremove (lua_State *L) { - int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; + int e = aux_getn(L, 1); int pos = luaL_optint(L, 2, e); - if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ - luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ + if (e == 0) return 0; /* table is `empty' */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ lua_rawgeti(L, 1, pos); /* result = t[pos] */ for ( ;possizek, 0); for (i=0; isizek; i++) { luaA_pushobject(L, p->k+i); - lua_rawseti(L, -2, i+LUA_FIRSTINDEX); + lua_rawseti(L, -2, i+1); } return 1; } diff --git a/lua.h b/lua.h index 698d5807..c7c17f49 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.203 2005/03/22 16:04:29 roberto Exp roberto $ +** $Id: lua.h,v 1.204 2005/03/23 17:51:11 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** http://www.lua.org mailto:info@lua.org @@ -83,9 +83,6 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); #define LUA_TTHREAD 8 -/* first index for arrays */ -#define LUA_FIRSTINDEX 1 - /* minimum Lua stack available to a C function */ #define LUA_MINSTACK 20 diff --git a/lvm.c b/lvm.c index 1fe0b420..5456e74d 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.33 2005/03/16 16:59:21 roberto Exp roberto $ +** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -760,7 +760,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { if (c == 0) c = cast(int, *pc++); runtime_check(L, ttistable(ra)); h = hvalue(ra); - last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1; + last = ((c-1)*LFIELDS_PER_FLUSH) + n; if (last > h->sizearray) /* needs more space? */ luaH_resizearray(L, h, last); /* pre-alloc it at once */ for (; n > 0; n--) {