lua-users home
lua-l archive

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


> > 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