Browse Source

no more LUA_FIRSTINDEX

v5-2
Roberto Ierusalimschy 20 years ago
parent
commit
ade585bdf9
  1. 8
      lbaselib.c
  2. 4
      ldo.c
  3. 20
      ltablib.c
  4. 4
      ltests.c
  5. 5
      lua.h
  6. 4
      lvm.c

8
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 ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -240,7 +240,7 @@ static int luaB_ipairs (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
lua_pushvalue(L, 1); /* state, */ lua_pushvalue(L, 1); /* state, */
lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ lua_pushinteger(L, 0); /* and initial value */
return 3; return 3;
} }
@ -340,12 +340,12 @@ static int luaB_getn (lua_State *L) {
static int luaB_unpack (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 e = luaL_optint(L, 3, -1);
int n; int n;
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
if (e == -1) if (e == -1)
e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; e = luaL_getn(L, 1);
n = e - i + 1; /* number of elements */ n = e - i + 1; /* number of elements */
if (n <= 0) return 0; /* empty range */ if (n <= 0) return 0; /* empty range */
luaL_checkstack(L, n, "table too big to unpack"); luaL_checkstack(L, n, "table too big to unpack");

4
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 ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -202,7 +202,7 @@ static StkId adjust_varargs (lua_State *L, int nfixargs, int actual,
luaC_checkGC(L); luaC_checkGC(L);
htab = luaH_new(L, nvar, 1); /* create `arg' table */ htab = luaH_new(L, nvar, 1); /* create `arg' table */
for (i=0; i<nvar; i++) /* put extra arguments into `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' */ /* store counter in field `n' */
setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
cast(lua_Number, nvar)); cast(lua_Number, nvar));

20
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 ** Library for Table Manipulation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -23,7 +23,7 @@ static int foreachi (lua_State *L) {
int i; int i;
int n = aux_getn(L, 1); int n = aux_getn(L, 1);
luaL_checktype(L, 2, LUA_TFUNCTION); 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_pushvalue(L, 2); /* function */
lua_pushinteger(L, i); /* 1st argument */ lua_pushinteger(L, i); /* 1st argument */
lua_rawgeti(L, 1, i); /* 2nd argument */ lua_rawgeti(L, 1, i); /* 2nd argument */
@ -73,7 +73,7 @@ static int setn (lua_State *L) {
static int tinsert (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 */ int pos; /* where to insert new element */
if (lua_isnone(L, 3)) /* called with only 2 arguments */ if (lua_isnone(L, 3)) /* called with only 2 arguments */
pos = e; /* insert new element at the end */ 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] */ 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 */ lua_rawseti(L, 1, pos); /* t[pos] = v */
return 0; return 0;
} }
static int tremove (lua_State *L) { 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); int pos = luaL_optint(L, 2, e);
if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ if (e == 0) return 0; /* table is `empty' */
luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ luaL_setn(L, 1, e - 1); /* t.n = n-1 */
lua_rawgeti(L, 1, pos); /* result = t[pos] */ lua_rawgeti(L, 1, pos); /* result = t[pos] */
for ( ;pos<e; pos++) { for ( ;pos<e; pos++) {
lua_rawgeti(L, 1, pos+1); lua_rawgeti(L, 1, pos+1);
@ -113,11 +113,11 @@ static int str_concat (lua_State *L) {
luaL_Buffer b; luaL_Buffer b;
size_t lsep; size_t lsep;
const char *sep = luaL_optlstring(L, 2, "", &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); int last = luaL_optint(L, 4, -2);
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
if (last == -2) if (last == -2)
last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; last = luaL_getn(L, 1);
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (; i <= last; i++) { for (; i <= last; i++) {
lua_rawgeti(L, 1, 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? */ if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
luaL_checktype(L, 2, LUA_TFUNCTION); luaL_checktype(L, 2, LUA_TFUNCTION);
lua_settop(L, 2); /* make sure there is two arguments */ lua_settop(L, 2); /* make sure there is two arguments */
auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); auxsort(L, 1, n);
return 0; return 0;
} }

4
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 ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -430,7 +430,7 @@ static int listk (lua_State *L) {
lua_createtable(L, p->sizek, 0); lua_createtable(L, p->sizek, 0);
for (i=0; i<p->sizek; i++) { for (i=0; i<p->sizek; i++) {
luaA_pushobject(L, p->k+i); luaA_pushobject(L, p->k+i);
lua_rawseti(L, -2, i+LUA_FIRSTINDEX); lua_rawseti(L, -2, i+1);
} }
return 1; return 1;
} }

5
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 ** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org ** 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 #define LUA_TTHREAD 8
/* first index for arrays */
#define LUA_FIRSTINDEX 1
/* minimum Lua stack available to a C function */ /* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20 #define LUA_MINSTACK 20

4
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 ** Lua virtual machine
** See Copyright Notice in lua.h ** 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++); if (c == 0) c = cast(int, *pc++);
runtime_check(L, ttistable(ra)); runtime_check(L, ttistable(ra));
h = hvalue(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? */ if (last > h->sizearray) /* needs more space? */
luaH_resizearray(L, h, last); /* pre-alloc it at once */ luaH_resizearray(L, h, last); /* pre-alloc it at once */
for (; n > 0; n--) { for (; n > 0; n--) {

Loading…
Cancel
Save