lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


于 2013-12-19 9:46, Isaf 写道:
when reach the end of the file, function io_readline return no value, not nil.
so that the sentence in the reference manual is not correct:
"When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file."

I'm sorry, but I cannot find the `io_readline' function in my Lua installation and the documentation.

After reading your message, I suppose you mean the iterator function returned by io.lines(some_file) by `io_readline', do you?

And yes, I checked and found that the iterator really returned *no value* rather than *nil* at EOF.

Although it has the same effect as long you use the iterator only in the context of *for* loop, I still think we need a change
either to the manual or to the implementation to make them consistent.

I personally prefer to change the implementation, as this comforms to the description of the *generic for statement*
and *iterator* in the manual:

 > [quoted from the reference manual]
 > The generic for statement works over functions, called iterators. On each iteration, the iterator function is called
 > to produce a new value, stopping when this new value is nil.
 > [...]