7

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Punkroku
  • 73
  • 7
  • Sorry for the Delay in saying thanks my brother broke my computer monitor. Ctrl D was the correct answer. – Punkroku Oct 10 '18 at 01:25

3 Answers3

4

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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • Thank you. Ctrl+D is what I was looking for. In Linux the Ctrl+Z returns to the prompt > ^Z [2]+ Stopped lua – Punkroku Sep 13 '13 at 01:07
  • Back to this can you help me create a shellscript or virus or deamon that will spam ctrl+C to SIGINT preventing any programs from running in terminal without explicit permission or disabling of this type of virus protection. I am not trying to kill the current program or break from it but do that to other terminal programs. – Punkroku Oct 10 '18 at 01:21
  • Thank you for that answer. PS i tried explaining the idea at tiny.cc/dfvp and github.com/punkroku/dfvp – Punkroku Oct 10 '18 at 01:22
3

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

greatwolf
  • 20,287
  • 13
  • 71
  • 105
  • Have you heard of autokey I want to use it with linux and spam ctrl C to prevent viruses. Or better if a terminal app runs then hold CTRL C or send pausebreak to keyboard buffer – Punkroku Oct 10 '18 at 01:24
0

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

DjAlan
  • 71
  • 3