3

The following command freezes on a string of length about 2000 chars:

lua -e 'print(io.read())'

Any idea why?

PS: Lua version 5.1.5

2 Answers 2

4

This is most probably a limitation of terminal IO in the underlying operating system. It is enforced before it gets to the Lua limit.

Try entering a long line in cat > /dev/null.

1
  • You're totally right: the input freezes just as in case of my lua script. Thank you very much! Oct 17, 2013 at 11:50
2

When called without arguments, io.read uses the default format "*l", which reads the next line. The underlying buffer size is C's BUFSIZ, it seems that your input string has exceeded that limit.

Change it to io.read("*a") to read the whole input. Remember to send EOF in the end.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.