diff options
-rw-r--r-- | lbaselib.c | 8 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | ltablib.c | 20 | ||||
-rw-r--r-- | ltests.c | 4 | ||||
-rw-r--r-- | lua.h | 5 | ||||
-rw-r--r-- | lvm.c | 4 |
6 files changed, 21 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.171 2005/03/16 16:58:41 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.172 2005/03/22 16:04:29 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 | */ |
@@ -240,7 +240,7 @@ static int luaB_ipairs (lua_State *L) { | |||
240 | luaL_checktype(L, 1, LUA_TTABLE); | 240 | luaL_checktype(L, 1, LUA_TTABLE); |
241 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ | 241 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ |
242 | lua_pushvalue(L, 1); /* state, */ | 242 | lua_pushvalue(L, 1); /* state, */ |
243 | lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ | 243 | lua_pushinteger(L, 0); /* and initial value */ |
244 | return 3; | 244 | return 3; |
245 | } | 245 | } |
246 | 246 | ||
@@ -340,12 +340,12 @@ static int luaB_getn (lua_State *L) { | |||
340 | 340 | ||
341 | 341 | ||
342 | static int luaB_unpack (lua_State *L) { | 342 | static int luaB_unpack (lua_State *L) { |
343 | int i = luaL_optint(L, 2, LUA_FIRSTINDEX); | 343 | int i = luaL_optint(L, 2, 1); |
344 | int e = luaL_optint(L, 3, -1); | 344 | int e = luaL_optint(L, 3, -1); |
345 | int n; | 345 | int n; |
346 | luaL_checktype(L, 1, LUA_TTABLE); | 346 | luaL_checktype(L, 1, LUA_TTABLE); |
347 | if (e == -1) | 347 | if (e == -1) |
348 | e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | 348 | e = luaL_getn(L, 1); |
349 | n = e - i + 1; /* number of elements */ | 349 | n = e - i + 1; /* number of elements */ |
350 | if (n <= 0) return 0; /* empty range */ | 350 | if (n <= 0) return 0; /* empty range */ |
351 | luaL_checkstack(L, n, "table too big to unpack"); | 351 | luaL_checkstack(L, n, "table too big to unpack"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.18 2005/03/16 20:02:48 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.19 2005/03/18 18:55:09 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 | */ |
@@ -202,7 +202,7 @@ static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, | |||
202 | luaC_checkGC(L); | 202 | luaC_checkGC(L); |
203 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ | 203 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
204 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ | 204 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
205 | setobj2n(L, luaH_setnum(L, htab, i+LUA_FIRSTINDEX), L->top - nvar + i); | 205 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); |
206 | /* store counter in field `n' */ | 206 | /* store counter in field `n' */ |
207 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), | 207 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), |
208 | cast(lua_Number, nvar)); | 208 | cast(lua_Number, nvar)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.28 2005/03/16 16:58:41 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 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=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { | 26 | for (i=1; i <= n; 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 */ |
@@ -73,7 +73,7 @@ static int setn (lua_State *L) { | |||
73 | 73 | ||
74 | 74 | ||
75 | static int tinsert (lua_State *L) { | 75 | static int tinsert (lua_State *L) { |
76 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ | 76 | int e = aux_getn(L, 1) + 1; /* first empty element */ |
77 | int pos; /* where to insert new element */ | 77 | int pos; /* where to insert new element */ |
78 | if (lua_isnone(L, 3)) /* called with only 2 arguments */ | 78 | if (lua_isnone(L, 3)) /* called with only 2 arguments */ |
79 | pos = e; /* insert new element at the end */ | 79 | pos = e; /* insert new element at the end */ |
@@ -87,17 +87,17 @@ static int tinsert (lua_State *L) { | |||
87 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ | 87 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ |
88 | } | 88 | } |
89 | } | 89 | } |
90 | luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */ | 90 | luaL_setn(L, 1, e); /* new size */ |
91 | lua_rawseti(L, 1, pos); /* t[pos] = v */ | 91 | lua_rawseti(L, 1, pos); /* t[pos] = v */ |
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | static int tremove (lua_State *L) { | 96 | static int tremove (lua_State *L) { |
97 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; | 97 | int e = aux_getn(L, 1); |
98 | int pos = luaL_optint(L, 2, e); | 98 | int pos = luaL_optint(L, 2, e); |
99 | if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ | 99 | if (e == 0) return 0; /* table is `empty' */ |
100 | luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ | 100 | luaL_setn(L, 1, e - 1); /* t.n = n-1 */ |
101 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ | 101 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ |
102 | for ( ;pos<e; pos++) { | 102 | for ( ;pos<e; pos++) { |
103 | lua_rawgeti(L, 1, pos+1); | 103 | lua_rawgeti(L, 1, pos+1); |
@@ -113,11 +113,11 @@ static int str_concat (lua_State *L) { | |||
113 | luaL_Buffer b; | 113 | luaL_Buffer b; |
114 | size_t lsep; | 114 | size_t lsep; |
115 | const char *sep = luaL_optlstring(L, 2, "", &lsep); | 115 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
116 | int i = luaL_optint(L, 3, LUA_FIRSTINDEX); | 116 | int i = luaL_optint(L, 3, 1); |
117 | int last = luaL_optint(L, 4, -2); | 117 | int last = luaL_optint(L, 4, -2); |
118 | luaL_checktype(L, 1, LUA_TTABLE); | 118 | luaL_checktype(L, 1, LUA_TTABLE); |
119 | if (last == -2) | 119 | if (last == -2) |
120 | last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | 120 | last = luaL_getn(L, 1); |
121 | luaL_buffinit(L, &b); | 121 | luaL_buffinit(L, &b); |
122 | for (; i <= last; i++) { | 122 | for (; i <= last; i++) { |
123 | lua_rawgeti(L, 1, i); | 123 | lua_rawgeti(L, 1, i); |
@@ -229,7 +229,7 @@ static int sort (lua_State *L) { | |||
229 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 229 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
230 | luaL_checktype(L, 2, LUA_TFUNCTION); | 230 | luaL_checktype(L, 2, LUA_TFUNCTION); |
231 | lua_settop(L, 2); /* make sure there is two arguments */ | 231 | lua_settop(L, 2); /* make sure there is two arguments */ |
232 | auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); | 232 | auxsort(L, 1, n); |
233 | return 0; | 233 | return 0; |
234 | } | 234 | } |
235 | 235 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.21 2005/03/16 16:58:41 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.22 2005/03/23 17:51:11 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 | */ |
@@ -430,7 +430,7 @@ static int listk (lua_State *L) { | |||
430 | lua_createtable(L, p->sizek, 0); | 430 | lua_createtable(L, p->sizek, 0); |
431 | for (i=0; i<p->sizek; i++) { | 431 | for (i=0; i<p->sizek; i++) { |
432 | luaA_pushobject(L, p->k+i); | 432 | luaA_pushobject(L, p->k+i); |
433 | lua_rawseti(L, -2, i+LUA_FIRSTINDEX); | 433 | lua_rawseti(L, -2, i+1); |
434 | } | 434 | } |
435 | return 1; | 435 | return 1; |
436 | } | 436 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.203 2005/03/22 16:04:29 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.204 2005/03/23 17:51:11 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
5 | ** http://www.lua.org mailto:info@lua.org | 5 | ** 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); | |||
83 | #define LUA_TTHREAD 8 | 83 | #define LUA_TTHREAD 8 |
84 | 84 | ||
85 | 85 | ||
86 | /* first index for arrays */ | ||
87 | #define LUA_FIRSTINDEX 1 | ||
88 | |||
89 | 86 | ||
90 | /* minimum Lua stack available to a C function */ | 87 | /* minimum Lua stack available to a C function */ |
91 | #define LUA_MINSTACK 20 | 88 | #define LUA_MINSTACK 20 |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.33 2005/03/16 16:59:21 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 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 | */ |
@@ -760,7 +760,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { | |||
760 | if (c == 0) c = cast(int, *pc++); | 760 | if (c == 0) c = cast(int, *pc++); |
761 | runtime_check(L, ttistable(ra)); | 761 | runtime_check(L, ttistable(ra)); |
762 | h = hvalue(ra); | 762 | h = hvalue(ra); |
763 | last = ((c-1)*LFIELDS_PER_FLUSH) + n + LUA_FIRSTINDEX - 1; | 763 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
764 | if (last > h->sizearray) /* needs more space? */ | 764 | if (last > h->sizearray) /* needs more space? */ |
765 | luaH_resizearray(L, h, last); /* pre-alloc it at once */ | 765 | luaH_resizearray(L, h, last); /* pre-alloc it at once */ |
766 | for (; n > 0; n--) { | 766 | for (; n > 0; n--) { |