diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-13 10:10:58 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-13 10:10:58 -0300 |
| commit | 8da6fe62d81b74086e1d3bd59b9c4e3b1067714b (patch) | |
| tree | 215d29170ecf414d4fbba544da39b96d263813ec | |
| parent | c18fe57e543dabb828ad64dc2d45d66fa0fae429 (diff) | |
| download | lua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.tar.gz lua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.tar.bz2 lua-8da6fe62d81b74086e1d3bd59b9c4e3b1067714b.zip | |
`nexti' returns correct indices
| -rw-r--r-- | lbaselib.c | 9 |
1 files changed, 5 insertions, 4 deletions
| @@ -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) { | |||
| 198 | static int luaB_nexti (lua_State *L) { | 198 | static 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 | } |
