Hi, I'm new to Nim, and found the language nice, and coming from Python, I'm
trying to port some apps, but I'm hitting lots of road blocks. This time, with
closures.
import os
from posix import onSignal, SIGINT
type
App = object
proc cleanup(app: App) =
discard
proc start*(app: var App) =
onSignal(SIGINT):
echo "Exiting: ", sig
app.cleanup
while true:
os.sleep(10000)
var app = App()
app.start
Run
The compiler complains that 'app' is of type <var App> which cannot be captured
as it would violate memory safety. I tried with system.closureScope, but it
fails as well with type mismatch: got <cint, proc (signal`gensym349052:
cint){.closure, gcsafe, locks: 0.}>. No idea why it doesn't match required type
for handler: proc (a: cint){.noconv.}.
So my question is, how do I capture the environment with onSignal?
I looked at
[https://forum.nim-lang.org/t/5564#34689](https://forum.nim-lang.org/t/5564#34689),
but I'm not sure if this will solve my case. Any insights?