diff options
-rw-r--r-- | lauxlib.c | 6 | ||||
-rw-r--r-- | lbaselib.c | 9 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | ltablib.c | 17 | ||||
-rw-r--r-- | ltests.c | 4 | ||||
-rw-r--r-- | luaconf.h | 6 | ||||
-rw-r--r-- | lvm.c | 11 |
7 files changed, 32 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.110 2004/03/23 16:38:43 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.111 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -308,13 +308,13 @@ LUALIB_API int luaL_getn (lua_State *L, int t) { | |||
308 | if ((n = checkint(L, 2)) >= 0) return n; | 308 | if ((n = checkint(L, 2)) >= 0) return n; |
309 | lua_getfield(L, t, "n"); /* else try t.n */ | 309 | lua_getfield(L, t, "n"); /* else try t.n */ |
310 | if ((n = checkint(L, 1)) >= 0) return n; | 310 | if ((n = checkint(L, 1)) >= 0) return n; |
311 | for (n = 1; ; n++) { /* else must count elements */ | 311 | for (n = LUA_FIRSTINDEX; ; n++) { /* else must count elements */ |
312 | lua_rawgeti(L, t, n); | 312 | lua_rawgeti(L, t, n); |
313 | if (lua_isnil(L, -1)) break; | 313 | if (lua_isnil(L, -1)) break; |
314 | lua_pop(L, 1); | 314 | lua_pop(L, 1); |
315 | } | 315 | } |
316 | lua_pop(L, 1); | 316 | lua_pop(L, 1); |
317 | return n - 1; | 317 | return n - LUA_FIRSTINDEX; |
318 | } | 318 | } |
319 | 319 | ||
320 | /* }====================================================== */ | 320 | /* }====================================================== */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.141 2004/03/26 13:25:17 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.142 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -257,7 +257,7 @@ static int luaB_ipairs (lua_State *L) { | |||
257 | luaL_checktype(L, 1, LUA_TTABLE); | 257 | luaL_checktype(L, 1, LUA_TTABLE); |
258 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ | 258 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ |
259 | lua_pushvalue(L, 1); /* state, */ | 259 | lua_pushvalue(L, 1); /* state, */ |
260 | lua_pushinteger(L, 0); /* and initial value */ | 260 | lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ |
261 | return 3; | 261 | return 3; |
262 | } | 262 | } |
263 | 263 | ||
@@ -347,11 +347,12 @@ static int luaB_assert (lua_State *L) { | |||
347 | 347 | ||
348 | 348 | ||
349 | static int luaB_unpack (lua_State *L) { | 349 | static int luaB_unpack (lua_State *L) { |
350 | int i = luaL_optint(L, 2, 1); | 350 | int i = luaL_optint(L, 2, LUA_FIRSTINDEX); |
351 | int e = luaL_optint(L, 3, -1); | 351 | int e = luaL_optint(L, 3, -1); |
352 | int n; | 352 | int n; |
353 | luaL_checktype(L, 1, LUA_TTABLE); | 353 | luaL_checktype(L, 1, LUA_TTABLE); |
354 | if (e == -1) e = luaL_getn(L, 1); | 354 | if (e == -1) |
355 | e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | ||
355 | n = e - i + 1; /* number of elements */ | 356 | n = e - i + 1; /* number of elements */ |
356 | if (n <= 0) return 0; /* empty range */ | 357 | if (n <= 0) return 0; /* empty range */ |
357 | luaL_checkstack(L, n, "table too big to unpack"); | 358 | luaL_checkstack(L, n, "table too big to unpack"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.2 2004/03/23 17:02:58 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.3 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -193,7 +193,7 @@ static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { | |||
193 | actual -= nfixargs; /* number of extra arguments */ | 193 | actual -= nfixargs; /* number of extra arguments */ |
194 | htab = luaH_new(L, actual, 1); /* create `arg' table */ | 194 | htab = luaH_new(L, actual, 1); /* create `arg' table */ |
195 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ | 195 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ |
196 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - actual + i); | 196 | setobj2n(L, luaH_setnum(L, htab, i+LUA_FIRSTINDEX), L->top - actual + i); |
197 | /* store counter in field `n' */ | 197 | /* store counter in field `n' */ |
198 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), | 198 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), |
199 | cast(lua_Number, actual)); | 199 | cast(lua_Number, actual)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.22 2003/10/07 20:13:41 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.23 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,7 +23,7 @@ static int luaB_foreachi (lua_State *L) { | |||
23 | int i; | 23 | int i; |
24 | int n = aux_getn(L, 1); | 24 | int n = aux_getn(L, 1); |
25 | luaL_checktype(L, 2, LUA_TFUNCTION); | 25 | luaL_checktype(L, 2, LUA_TFUNCTION); |
26 | for (i=1; i<=n; i++) { | 26 | for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { |
27 | lua_pushvalue(L, 2); /* function */ | 27 | lua_pushvalue(L, 2); /* function */ |
28 | lua_pushinteger(L, i); /* 1st argument */ | 28 | lua_pushinteger(L, i); /* 1st argument */ |
29 | lua_rawgeti(L, 1, i); /* 2nd argument */ | 29 | lua_rawgeti(L, 1, i); /* 2nd argument */ |
@@ -109,16 +109,17 @@ static int str_concat (lua_State *L) { | |||
109 | luaL_Buffer b; | 109 | luaL_Buffer b; |
110 | size_t lsep; | 110 | size_t lsep; |
111 | const char *sep = luaL_optlstring(L, 2, "", &lsep); | 111 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
112 | int i = luaL_optint(L, 3, 1); | 112 | int i = luaL_optint(L, 3, LUA_FIRSTINDEX); |
113 | int n = luaL_optint(L, 4, 0); | 113 | int last = luaL_optint(L, 4, -2); |
114 | luaL_checktype(L, 1, LUA_TTABLE); | 114 | luaL_checktype(L, 1, LUA_TTABLE); |
115 | if (n == 0) n = luaL_getn(L, 1); | 115 | if (last == -2) |
116 | last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | ||
116 | luaL_buffinit(L, &b); | 117 | luaL_buffinit(L, &b); |
117 | for (; i <= n; i++) { | 118 | for (; i <= last; i++) { |
118 | lua_rawgeti(L, 1, i); | 119 | lua_rawgeti(L, 1, i); |
119 | luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings"); | 120 | luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings"); |
120 | luaL_addvalue(&b); | 121 | luaL_addvalue(&b); |
121 | if (i != n) | 122 | if (i != last) |
122 | luaL_addlstring(&b, sep, lsep); | 123 | luaL_addlstring(&b, sep, lsep); |
123 | } | 124 | } |
124 | luaL_pushresult(&b); | 125 | luaL_pushresult(&b); |
@@ -224,7 +225,7 @@ static int luaB_sort (lua_State *L) { | |||
224 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 225 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
225 | luaL_checktype(L, 2, LUA_TFUNCTION); | 226 | luaL_checktype(L, 2, LUA_TFUNCTION); |
226 | lua_settop(L, 2); /* make sure there is two arguments */ | 227 | lua_settop(L, 2); /* make sure there is two arguments */ |
227 | auxsort(L, 1, n); | 228 | auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); |
228 | return 0; | 229 | return 0; |
229 | } | 230 | } |
230 | 231 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.4 2004/03/23 17:07:53 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.5 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -418,7 +418,7 @@ static int listk (lua_State *L) { | |||
418 | lua_createtable(L, p->sizek, 0); | 418 | lua_createtable(L, p->sizek, 0); |
419 | for (i=0; i<p->sizek; i++) { | 419 | for (i=0; i<p->sizek; i++) { |
420 | luaA_pushobject(L, p->k+i); | 420 | luaA_pushobject(L, p->k+i); |
421 | lua_rawseti(L, -2, i+1); | 421 | lua_rawseti(L, -2, i+LUA_FIRSTINDEX); |
422 | } | 422 | } |
423 | return 1; | 423 | return 1; |
424 | } | 424 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.1 2004/05/03 12:28:43 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.2 2004/05/10 13:58:26 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -51,6 +51,10 @@ | |||
51 | /* buffer size used by lauxlib buffer system */ | 51 | /* buffer size used by lauxlib buffer system */ |
52 | #define LUAL_BUFFERSIZE BUFSIZ | 52 | #define LUAL_BUFFERSIZE BUFSIZ |
53 | 53 | ||
54 | |||
55 | /* first index for arrays */ | ||
56 | #define LUA_FIRSTINDEX 1 | ||
57 | |||
54 | /* }====================================================== */ | 58 | /* }====================================================== */ |
55 | 59 | ||
56 | 60 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.3 2004/03/26 14:02:41 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.4 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -694,7 +694,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
694 | case OP_SETLIST: | 694 | case OP_SETLIST: |
695 | case OP_SETLISTO: { | 695 | case OP_SETLISTO: { |
696 | int bc = GETARG_Bx(i); | 696 | int bc = GETARG_Bx(i); |
697 | int n; | 697 | int n, last; |
698 | Table *h; | 698 | Table *h; |
699 | runtime_check(L, ttistable(ra)); | 699 | runtime_check(L, ttistable(ra)); |
700 | h = hvalue(ra); | 700 | h = hvalue(ra); |
@@ -705,11 +705,12 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
705 | L->top = L->ci->top; | 705 | L->top = L->ci->top; |
706 | } | 706 | } |
707 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ | 707 | bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ |
708 | if (bc+n > h->sizearray) /* needs more space? */ | 708 | last = bc + n + LUA_FIRSTINDEX - 1; |
709 | luaH_resize(L, h, bc+n, h->lsizenode); /* pre-alloc it at once */ | 709 | if (last > h->sizearray) /* needs more space? */ |
710 | luaH_resize(L, h, last, h->lsizenode); /* pre-alloc it at once */ | ||
710 | for (; n > 0; n--) { | 711 | for (; n > 0; n--) { |
711 | TValue *val = ra+n; | 712 | TValue *val = ra+n; |
712 | setobj2t(L, luaH_setnum(L, h, bc+n), val); | 713 | setobj2t(L, luaH_setnum(L, h, last--), val); |
713 | luaC_barrier(L, h, val); | 714 | luaC_barrier(L, h, val); |
714 | } | 715 | } |
715 | break; | 716 | break; |