[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: how io.read() will return nil ?
- From: "Jeff Pohlmeyer" <yetanothergeek@...>
- Date: Sun, 24 Aug 2008 06:16:41 -0500
Shmuel Zeigerman wrote:
> Jeff Pohlmeyer wrote:
>> I think you want to test for empty string, that is not the same as nil.
> Empty string in Lua usually isn't considered as "no value", it is just one
> of all the possible strings.
> In Windows, the end of input is Ctrl-Z, in Linux - Ctrl-D (not sure in the
Right, but I thought it would be easier on the user to
simply press "Return" to break the loop, which gives
the zero-length string. But you raise a good point,
my previous version gives a run time error if it
actually does encounter an EOF.
So maybe this is better:
for count = 1, math.huge do
local line = io.read()
if line==nil or #line==0 then break end
io.write(string.format("%6d ", count), line, "\n")