lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>Why, when I run the following:
>
>lua -e "io.stdin:read '*a'"
>
>do I need to press Ctrl+C twice to escape?

Because lua (the interpreter) can only stop when control handed is back to Lua
(the core) because Lua needs to ensure that the state is consistent. The first
Ctrl+C sets things up so that the thread can be interrupted when the time is
right (that is, when we get back to the Lua VM). It also resets the Ctrl+C
handler to the default, so as not to get into a loop. So, your second Ctrl+C
silently aborts the program because control is still in C (inside fread most
probably).

Try pressing one Ctrl+C and then Ctrl+D to return from fread. Then you'll see
the "interrupted!" message issued from lua.

If you interrupt a C routine that takes a long time then you'll probably
become impatient and hit Ctrl+C twice, in which case the program will be
aborted silently. If you are patient, then you'll see the "interrupted!"
message. Try

	lua -e "a=string.rep('a',1e8)"

--lhf