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
38.9k25 gold badges206 silver badges281 bronze badges
asked Sep 12, 2013 at 22:20
1
  • Sorry for the Delay in saying thanks my brother broke my computer monitor. Ctrl D was the correct answer. Commented Oct 10, 2018 at 1:25

3 Answers 3

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.

answered Sep 13, 2013 at 1:01
3
  • Thank you. Ctrl+D is what I was looking for. In Linux the Ctrl+Z returns to the prompt > ^Z [2]+ Stopped lua Commented Sep 13, 2013 at 1: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. Commented Oct 10, 2018 at 1:21
  • Thank you for that answer. PS i tried explaining the idea at tiny.cc/dfvp and github.com/punkroku/dfvp Commented Oct 10, 2018 at 1:22
3

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

answered Sep 12, 2013 at 23:28
1
  • 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 Commented Oct 10, 2018 at 1: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.

answered Sep 18, 2020 at 16:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.