aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-07 14:42:05 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-07 14:42:05 -0200
commit7f6f70853c8a2730fca2e95d5968ad52cf470bda (patch)
tree948147a9cf6a5c5eb34232e7547c310eb06eadea /liolib.c
parentb8fed93215a23a3f443c5b0126f0de1725771b44 (diff)
downloadlua-7f6f70853c8a2730fca2e95d5968ad52cf470bda.tar.gz
lua-7f6f70853c8a2730fca2e95d5968ad52cf470bda.tar.bz2
lua-7f6f70853c8a2730fca2e95d5968ad52cf470bda.zip
To-be-closed variable in 'for' loop separated from the state
The variable to be closed in a generic 'for' loop now is the 4th value produced in the loop initialization, instead of being the loop state (the 2nd value produced). That allows a loop to use a state with a '__toclose' metamethod but do not close it. (As an example, 'f:lines()' might use the file 'f' as a state for the loop, but it should not close the file when the loop ends.)
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/liolib.c b/liolib.c
index b2a2fec8..7d6d51e6 100644
--- a/liolib.c
+++ b/liolib.c
@@ -386,8 +386,10 @@ static int io_lines (lua_State *L) {
386 } 386 }
387 aux_lines(L, toclose); /* push iteration function */ 387 aux_lines(L, toclose); /* push iteration function */
388 if (toclose) { 388 if (toclose) {
389 lua_pushvalue(L, 1); /* file will be second result */ 389 lua_pushnil(L); /* state */
390 return 2; 390 lua_pushnil(L); /* control */
391 lua_pushvalue(L, 1); /* file is the to-be-closed variable (4th result) */
392 return 4;
391 } 393 }
392 else 394 else
393 return 1; 395 return 1;