proc times(x:int) : proc(y:int):int = # curry-ed application
return proc(y:int):int = x*y
var fn = times(6) # the closure
echo fn(3) # it works
var rawP = fn.rawProc()
var rawE = fn.rawEnv()
echo cast[proc(env:pointer,y:int):int](rawP)(rawE,3) # THIS FAILS
The error is caught in the c compiler - since cast hides it from nim???
This doesn't answer your question directly, but is working code for an IUP callback
proc toCB(fp: proc): ICallback =
return cast[ICallback](fp)
var btnFull = button("Full screen","")
proc doFull(ih:PIhandle): cint {.cdecl.} =
setAttribute(dlg,"FULLSCREEN","YES")
return IUP_DEFAULT
discard setCallback(btnFull,"ACTION", toCB(doFull))
IUP attributes are text, but your callback is a Nim procvar (?).
I am guessing you are wanting to save the callback as an attribute of an IUP object (which is text), and you will have to convert between that text and a Nim procvar
env pointer should be the last param and the callconv should be .nimcall.
type
abcd = proc(a: int, x:pointer): int {.nimcall.}
echo cast[abcd](rawP)(3, rawE)
and the documentation should be clear on this topic, but it is not :)