Created
October 30, 2016 23:37
-
-
Save singularperturbation/3beddef7fca799dc7ea6107eb04f401c to your computer and use it in GitHub Desktop.
setControlCHook with lambda referencing local variables
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
import asyncdispatch | |
# Compiles if declared as global here: | |
# | |
# var toChange = false | |
proc main() = | |
var toChange = false | |
# This does not work (but does with {.noconv.} if taking out reference to | |
# `toChange` or if `toChange` is a global. | |
# | |
# test.nim(9, 18) Error: type mismatch: got (hook: proc (){.closure, gcsafe, locks: 0.}) | |
# but expected one of: | |
# proc setControlCHook(hook: proc () not nil) | |
setControlCHook(hook = | |
proc() {.noconv.} = | |
toChange = true | |
echo "Quitting: " & $toChange | |
quit(0) | |
) | |
runForever() | |
when isMainModule: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment