I wish to pass a lostanza
function to a C API, where it will be called from C.
This is my current implementation :
; callbacks.stanza
defpackage callbacks :
import core
extern call_from_c : (ptr<(() -> int)>) -> int
lostanza defn my-callback () -> int :
return 42
lostanza defn call-from-c () -> ref<Int> :
val ret = call-c call_from_c(addr(my-callback))
return new Int{ret}
println(call-from-c())
With corresponding C file :
// call_from_c.c
int call_from_c (int (*callback)()) {
return callback();
}
I compile this code with stanza callbacks.stanza -ccfiles call_from_c.c -o cbk
, but when running it I get this error message :
$ ./cbk
FATAL ERROR: Stack overflow
in core/fatal!
at core/core.stanza:374.2
in core/extend-stack
at core/core.stanza:2438.9
Segmentation fault (core dumped)
What do I need to be doing in order to set up the call to lostanza from C?