Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interrupting lua interpretation without ctrl -c quitting

I am running code from the book programming in Lua... http://www.lua.org/pil/3.6.html

when I run this code in the terminal interpreter... it continues reading input forever...

list = nil
    for line in io.lines() do
      list = {next=list, value=line}
end

Ctrl C returns me to the prompt/bash. Is there another command to break? How do I break/return from a chunk of lua code without exiting the interpreter?

like image 571
Punkroku Avatar asked Sep 12 '13 22:09

Punkroku


2 Answers

By pressing Ctrl-C in a Unix-like system, you are sending your process the signal of SIGINT, which by default will terminate the process.

Your program continues reading from input forever because it's blocking in the call of io.lines(), which keeps reading from standard input. To interrupt it, send your terminal an EOF, this is done by pressing Ctrl-D in a Unix-like system.

On Windows, the key to send EOF is Ctrl-Z.

like image 91
Yu Hao Avatar answered Oct 24 '22 08:10

Yu Hao


You can indicate the end of input for stdin by using either Ctrl-Z or Ctrl-D.

like image 41
greatwolf Avatar answered Oct 24 '22 07:10

greatwolf