diff options
Diffstat (limited to '')
| -rw-r--r-- | lbaselib.c | 13 |
1 files changed, 7 insertions, 6 deletions
| @@ -279,21 +279,22 @@ static int luaB_next (lua_State *L) { | |||
| 279 | 279 | ||
| 280 | static int pairscont (lua_State *L, int status, lua_KContext k) { | 280 | static int pairscont (lua_State *L, int status, lua_KContext k) { |
| 281 | (void)L; (void)status; (void)k; /* unused */ | 281 | (void)L; (void)status; (void)k; /* unused */ |
| 282 | return 3; | 282 | return 4; /* __pairs did all the work, just return its results */ |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | static int luaB_pairs (lua_State *L) { | 285 | static int luaB_pairs (lua_State *L) { |
| 286 | luaL_checkany(L, 1); | 286 | luaL_checkany(L, 1); |
| 287 | if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */ | 287 | if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */ |
| 288 | lua_pushcfunction(L, luaB_next); /* will return generator, */ | 288 | lua_pushcfunction(L, luaB_next); /* will return generator and */ |
| 289 | lua_pushvalue(L, 1); /* state, */ | 289 | lua_pushvalue(L, 1); /* state */ |
| 290 | lua_pushnil(L); /* and initial value */ | 290 | lua_pushnil(L); /* initial value */ |
| 291 | lua_pushnil(L); /* to-be-closed object */ | ||
| 291 | } | 292 | } |
| 292 | else { | 293 | else { |
| 293 | lua_pushvalue(L, 1); /* argument 'self' to metamethod */ | 294 | lua_pushvalue(L, 1); /* argument 'self' to metamethod */ |
| 294 | lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */ | 295 | lua_callk(L, 1, 4, 0, pairscont); /* get 4 values from metamethod */ |
| 295 | } | 296 | } |
| 296 | return 3; | 297 | return 4; |
| 297 | } | 298 | } |
| 298 | 299 | ||
| 299 | 300 | ||
