diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-11-11 15:11:06 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-11-11 15:11:06 -0300 |
| commit | 4cf498210e6a60637a7abb06d32460ec21efdbdc (patch) | |
| tree | 7b9cffee61083a6b256311917019b58a1fbdd42a /lbaselib.c | |
| parent | 5b7d9987642f72d44223a8e5e79e013bb2b3d579 (diff) | |
| download | lua-4cf498210e6a60637a7abb06d32460ec21efdbdc.tar.gz lua-4cf498210e6a60637a7abb06d32460ec21efdbdc.tar.bz2 lua-4cf498210e6a60637a7abb06d32460ec21efdbdc.zip | |
Diffstat (limited to 'lbaselib.c')
| -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 | ||
