summaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-13 10:10:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-13 10:10:58 -0300
commit8da6fe62d81b74086e1d3bd59b9c4e3b1067714b (patch)
tree215d29170ecf414d4fbba544da39b96d263813ec /lbaselib.c
parentc18fe57e543dabb828ad64dc2d45d66fa0fae429 (diff)
downloadlua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.tar.gz
lua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.tar.bz2
lua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.zip
`nexti' returns correct indices
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lbaselib.c b/lbaselib.c
index a92f785d..cdfa3d33 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.71 2002/05/02 17:12:27 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.72 2002/05/06 19:05:10 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*/
@@ -198,14 +198,15 @@ static int luaB_next (lua_State *L) {
198static int luaB_nexti (lua_State *L) { 198static int luaB_nexti (lua_State *L) {
199 lua_Number i = lua_tonumber(L, 2); 199 lua_Number i = lua_tonumber(L, 2);
200 luaL_check_type(L, 1, LUA_TTABLE); 200 luaL_check_type(L, 1, LUA_TTABLE);
201 if (i == 0) { /* `for' start? */ 201 if (i == 0 && lua_isnull(L, 2)) { /* `for' start? */
202 lua_getglobal(L, "nexti"); /* return generator, */ 202 lua_getglobal(L, "nexti"); /* return generator, */
203 lua_pushvalue(L, 1); /* state, */ 203 lua_pushvalue(L, 1); /* state, */
204 lua_pushnumber(L, 1); /* and initial value */ 204 lua_pushnumber(L, 0); /* and initial value */
205 return 3; 205 return 3;
206 } 206 }
207 else { /* `for' step */ 207 else { /* `for' step */
208 lua_pushnumber(L, i+1); /* next value */ 208 i++; /* next value */
209 lua_pushnumber(L, i);
209 lua_rawgeti(L, 1, i); 210 lua_rawgeti(L, 1, i);
210 return (lua_isnil(L, -1)) ? 0 : 2; 211 return (lua_isnil(L, -1)) ? 0 : 2;
211 } 212 }