[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: io.read("*n") doesn't read after number parsing error
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 1 Mar 2015 12:13:04 -0300
> > So, if the input is not a number, I can get it as a string.
> > Thank you for the explanation!
> >
>
> Right. It helps to remember that stdin is an input stream, just like a
> file. So if io.read('*n') doesn't remove any characters from the input
> buffer, then the next io.read() will see those same characters.
Just a small caveat: io.read('*n') reads as much of the input as looks
like a number. If the final result is not a number, it can fail and
still remove stuff from the input:
> print(io.read'*n'); print(#io.read'*l')
0x
--> nil
--> 0
-- Roberto