proc callback(arg: cint; arg2: cstring) {.cdecl.} =
setupForeignThreadGc()
# ... more code here
toC(callback)
I was just looking into this at this very moment and I am not sure if I use it well.
I was reading the Thread coordination section and this forum entry.
So I was implementing the following:
proc callback( userData: pointer,
f: ptr VSFrameRef,
n: cint,
a4: ptr VSNodeRef,
errorMsg: cstring) {.cdecl.} =
setupForeignThreadGc() #<---------------------
API.freeFrame( f )
tearDownForeignThreadGc() #<---------------------
proc NullAsync*(vsmap:ptr VSMap):int =
let node = getFirstNode(vsmap)
#API.freeMap(vsmap)
let vinfo = API.getVideoInfo(node) # video info pointer
let nframes = vinfo.numFrames
for i in 0..<nframes:
API.getFrameAsync( i, node, callback, nil) # getFrameAsync is part of the API and calls the callback.
API.freeMap(vsmap)
API.freeNode(node)
return nframes
Right now it fails. I am compiling with --threads:on.
I am not sure if I am not using it as I should or if I am not using properly the VapourSynth's API.
}
logic.nim: {. compile: "logic.c" .} type adder {. importc .} = proc(a, b: cint): cint proc run(fn: adder, a, b: cint): cint {. importc, cdecl, nodecl .} proc add(a, b: cint): cint {. cdecl .} = a+b
var res=int(run(add, cint(100), cint(5125))) echo $res