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.)
diff --git a/liolib.c b/liolib.c
index 83fbb17..56507d5 100644
--- a/liolib.c
+++ b/liolib.c
@@ -624,7 +624,7 @@
lua_pushvalue(L, lua_upvalueindex(3 + i));
n = g_read(L, p->f, 2); /* 'n' is number of results */
lua_assert(n > 0); /* should return at least a nil */
- if (lua_toboolean(L, -n)) /* read at least one value? */
+ if (!lua_isnil(L, -n)) /* read at least one value? */
return n; /* return them */
else { /* first result is nil: EOF or error */
if (n > 1) { /* is there error information? */
diff --git a/manual/manual.of b/manual/manual.of
index 8eebe9c..c1ee8eb 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -7926,8 +7926,8 @@
Opens the given file name in read mode
and returns an iterator function that
works like @T{file:lines(@Cdots)} over the opened file.
-When the iterator function detects the end of file,
-it returns no values (to finish the loop) and automatically closes the file.
+When the iterator function fails to read any value,
+it automatically closes the file.
Besides the iterator function,
@id{io.lines} returns three other values:
two @nil values as placeholders,
@@ -7941,7 +7941,8 @@
that is, it iterates over the lines of the default input file.
In this case, the iterator does not close the file when the loop ends.
-In case of errors this function raises the error,
+In case of errors opening the file,
+this function raises the error,
instead of returning an error code.
}
@@ -8053,9 +8054,6 @@
Unlike @Lid{io.lines}, this function does not close the file
when the loop ends.
-In case of errors this function raises the error,
-instead of returning an error code.
-
}
@LibEntry{file:read (@Cdots)|