lua

A copy of the Lua development repository
Log | Files | Refs | README

commit ade585bdf9e286a0ec01796763ded6701c6b1a8f
parent 04c41444e22740119d3c017830276d6590b09747
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon, 28 Mar 2005 14:17:31 -0300

no more LUA_FIRSTINDEX

Diffstat:
Mlbaselib.c | 8++++----
Mldo.c | 4++--
Mltablib.c | 20++++++++++----------
Mltests.c | 4++--
Mlua.h | 5+----
Mlvm.c | 4++--
6 files changed, 21 insertions(+), 24 deletions(-)

diff --git 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 @@ -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; i<nvar; i++) /* put extra arguments into `arg' table */ - setobj2n(L, luaH_setnum(L, htab, i+LUA_FIRSTINDEX), L->top - 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 @@ -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 ( ;pos<e; pos++) { lua_rawgeti(L, 1, pos+1); @@ -113,11 +113,11 @@ static int str_concat (lua_State *L) { luaL_Buffer b; size_t lsep; const char *sep = luaL_optlstring(L, 2, "", &lsep); - int i = luaL_optint(L, 3, LUA_FIRSTINDEX); + int i = luaL_optint(L, 3, 1); int last = luaL_optint(L, 4, -2); luaL_checktype(L, 1, LUA_TTABLE); if (last == -2) - last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; + last = luaL_getn(L, 1); luaL_buffinit(L, &b); for (; i <= last; i++) { lua_rawgeti(L, 1, i); @@ -229,7 +229,7 @@ static int sort (lua_State *L) { if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ luaL_checktype(L, 2, LUA_TFUNCTION); lua_settop(L, 2); /* make sure there is two arguments */ - auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); + auxsort(L, 1, n); return 0; } diff --git a/ltests.c b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.21 2005/03/16 16:58:41 roberto Exp roberto $ +** $Id: ltests.c,v 2.22 2005/03/23 17:51:11 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -430,7 +430,7 @@ static int listk (lua_State *L) { lua_createtable(L, p->sizek, 0); for (i=0; i<p->sizek; 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 @@ -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 @@ -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--) {