diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 11:41:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-31 11:41:59 -0300 |
| commit | 223bb04090344b1972dc2a7910a54b46210f0d40 (patch) | |
| tree | 4346fc4bfb9b32a6502a61f97f01f225ee4f7830 | |
| parent | fe040633a1d64af4c19acc4707adb47413a3cd4a (diff) | |
| download | lua-223bb04090344b1972dc2a7910a54b46210f0d40.tar.gz lua-223bb04090344b1972dc2a7910a54b46210f0d40.tar.bz2 lua-223bb04090344b1972dc2a7910a54b46210f0d40.zip | |
Correction in the documentation of 'io.lines'
The loop does not end on end of file, but when the iterator function
fails to read a value. (In particular, the format "a" never fails,
so a loop with 'io.lines(fname, "a")' never ends.)
Diffstat (limited to '')
| -rw-r--r-- | liolib.c | 2 | ||||
| -rw-r--r-- | manual/manual.of | 10 |
2 files changed, 5 insertions, 7 deletions
| @@ -624,7 +624,7 @@ static int io_readline (lua_State *L) { | |||
| 624 | lua_pushvalue(L, lua_upvalueindex(3 + i)); | 624 | lua_pushvalue(L, lua_upvalueindex(3 + i)); |
| 625 | n = g_read(L, p->f, 2); /* 'n' is number of results */ | 625 | n = g_read(L, p->f, 2); /* 'n' is number of results */ |
| 626 | lua_assert(n > 0); /* should return at least a nil */ | 626 | lua_assert(n > 0); /* should return at least a nil */ |
| 627 | if (lua_toboolean(L, -n)) /* read at least one value? */ | 627 | if (!lua_isnil(L, -n)) /* read at least one value? */ |
| 628 | return n; /* return them */ | 628 | return n; /* return them */ |
| 629 | else { /* first result is nil: EOF or error */ | 629 | else { /* first result is nil: EOF or error */ |
| 630 | if (n > 1) { /* is there error information? */ | 630 | if (n > 1) { /* is there error information? */ |
diff --git a/manual/manual.of b/manual/manual.of index 8eebe9cb..c1ee8eb7 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
| @@ -7926,8 +7926,8 @@ instead of returning an error code. | |||
| 7926 | Opens the given file name in read mode | 7926 | Opens the given file name in read mode |
| 7927 | and returns an iterator function that | 7927 | and returns an iterator function that |
| 7928 | works like @T{file:lines(@Cdots)} over the opened file. | 7928 | works like @T{file:lines(@Cdots)} over the opened file. |
| 7929 | When the iterator function detects the end of file, | 7929 | When the iterator function fails to read any value, |
| 7930 | it returns no values (to finish the loop) and automatically closes the file. | 7930 | it automatically closes the file. |
| 7931 | Besides the iterator function, | 7931 | Besides the iterator function, |
| 7932 | @id{io.lines} returns three other values: | 7932 | @id{io.lines} returns three other values: |
| 7933 | two @nil values as placeholders, | 7933 | two @nil values as placeholders, |
| @@ -7941,7 +7941,8 @@ to @T{io.input():lines("l")}; | |||
| 7941 | that is, it iterates over the lines of the default input file. | 7941 | that is, it iterates over the lines of the default input file. |
| 7942 | In this case, the iterator does not close the file when the loop ends. | 7942 | In this case, the iterator does not close the file when the loop ends. |
| 7943 | 7943 | ||
| 7944 | In case of errors this function raises the error, | 7944 | In case of errors opening the file, |
| 7945 | this function raises the error, | ||
| 7945 | instead of returning an error code. | 7946 | instead of returning an error code. |
| 7946 | 7947 | ||
| 7947 | } | 7948 | } |
| @@ -8053,9 +8054,6 @@ starting at the current position. | |||
| 8053 | Unlike @Lid{io.lines}, this function does not close the file | 8054 | Unlike @Lid{io.lines}, this function does not close the file |
| 8054 | when the loop ends. | 8055 | when the loop ends. |
| 8055 | 8056 | ||
| 8056 | In case of errors this function raises the error, | ||
| 8057 | instead of returning an error code. | ||
| 8058 | |||
| 8059 | } | 8057 | } |
| 8060 | 8058 | ||
| 8061 | @LibEntry{file:read (@Cdots)| | 8059 | @LibEntry{file:read (@Cdots)| |
