lua-users home
lua-l archive

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


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
> latter).


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")
end


- Jeff