Created
April 7, 2011 21:32
-
-
Save dom96/908782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Module for handling and raising signals. Wraps ``<signals.h>``. | |
type | |
TSignal = enum | |
SIGINT = 2 | |
proc signal*(sig: cint, func: pointer) {.importc: "signal", header: "<signal.h>".} | |
template atSignal*(s: TSignal, actions: stmt): stmt = | |
proc callback(sig: cint) = | |
actions | |
signal(int(s), callback) | |
when isMainModule: | |
atSignal(SIGINT): | |
echo("Called back!") | |
quit() | |
while True: | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the same example using sigaction instead of signal, and using the Nim
posix
module. I learn thatsignal
is deprecated andsigaction
should be used instead: