interrupting lua interpretation without ctrl -c quitting

1.2k views Asked by At

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?

3

There are 3 answers

1
greatwolf On

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

3
Yu Hao On

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.

0
DjAlan On

CTRL-U deletes all the characters before the cursor position, therefore the whole line. It also works like this in a Linux shell.