[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Trapping Control-C in an interactive Lua program
- From: Richard Hundt <richardhundt@...>
- Date: Mon, 12 Apr 2010 19:25:06 +0200
Hi Steve,
steve donovan wrote:
Hi all,
This is ultimately not a Lua-specific problem, but here we go:
sometimes you need an interactive Lua program that doesn't quietly die
on control-C.
I've tried using SetConsoleCtrlHandler(nil,1) and
signal(SIGINT,SIG_IGN) using Alien, and no go.
Obviously I could change lua.c to get the behaviour I need, but
naturally I would prefer not to.
steve d.
With luasys [1] it'd look like this (taken verbatim from the included
tests):
print"-- Signal: wait SIGINT"
do
local function on_signal(evq, evid, _, _, _, timeout)
if timeout then
assert(evq:timeout(evid))
assert(evq:ignore_signal("INT", false))
print"SIGINT enabled. Please, press Ctrl-C..."
else
print"Thanks!"
end
end
local evq = assert(sys.event_queue())
assert(evq:add_signal("INT", on_signal, 3000, true))
assert(evq:ignore_signal("INT", true))
evq:loop(10000)
print"OK"
end
Dunno what your feelings are on using luasys, but just thought I'd add
it into the mix.
Cheers,
Rich
[1] http://luaforge.net/projects/luasys/