lua-users home
lua-l archive

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


2015-03-29 14:33 GMT+02:00 Soni L. <fakedme@gmail.com>:

> The Lua 5.2 manual is not clear whether io.lines(nil, ...) is valid, it only
> says `The call io.lines() (with no file name) is equivalent to
> io.input():lines(); that is, it iterates over the lines of the default input
> file. In this case it does not close the file when the loop ends.`
>
> Could it be that the reference implementation deviates from the reference
> manual? Or is there something I missed?

The usual Lua convention is that a `nil` argument means that the
default value will be used. When that convention is adhered to,
the manual does not need to spell it out.

Here, there is an obvious need for io.lines(nil, ...), since the other
parameters may be non-default.

> for k in io.lines(nil,5) do print(k) end
abcdefghi
abcde
fghi

In the above, `abcdefghi` is the user input, and the iterator
makes two items of it as per format.