Araq, the deepCopy() part works fine with string and int parameters, but
unfortunately not with objects. I got it working, when I substitute at by
"ParObj" literal everywhere: (Of course that makes no sense for general use
case)
type
ParObj = object
x: float
proc clicked(button: XButton; arg: ParObj) =
echo arg.x
echo button.x
macro connect(widget: Widget; signal: string; p: untyped; arg: typed):
typed =
inc(ProcID)
let wt = getType(widget) # widget type
let at = getType(arg) # argument type
let signalName = ($signal).replace("-", "_") # maybe we should just use
plain proc names
let procNameCdecl = newIdentNode("connect_for_signal_cdecl_" & signalName
& $ProcID)
let procName = newIdentNode("connect_for_signal_" & signalName & $ProcID)
let scName = newIdentNode("sc" & signalName)
result = quote do:
proc `procNameCdecl`(button: ptr Object00 , data: pointer) {.cdecl.} =
var h: pointer = g_object_get_qdata(button, Quark)
`p`(cast[`wt`](h), cast[ParObj](data))
#`p`(cast[`wt`](h), cast[`at`](data))
proc `procName`(self: `wt`; p: proc (self: `wt`, arg: ParObj); a:
ParObj) =
when false:#compiles(GC_ref(a)):
GC_ref(a)
`scName`(self, `procNameCdecl`, cast[pointer](a))
else:
#var ar: ref `at`
var ar: ref ParObj
new(ar)
deepCopy(ar[], a)
`scName`(self, `procNameCdecl`, cast[pointer](ar[]))
`procName`(`widget`, `p`, `arg`)
connect(button1, "clicked", clicked, parObj)
So "let at = getType(arg)" in macro and using at is not identical to ParObj.
While for base types int and strings it works. I have the feeling that
getType() gives only plain object type. Is there a way to get real object type,
which is ParObj here?