foreach macro fix for strings
This commit is contained in:
parent
221b212334
commit
f87aeda345
1 changed files with 12 additions and 6 deletions
|
|
@ -420,11 +420,17 @@ macro foreach*(container: gtk.Container; p: untyped; arg: typed): untyped =
|
||||||
let procNameCdecl = "foreach_cdecl_" & $foreachID
|
let procNameCdecl = "foreach_cdecl_" & $foreachID
|
||||||
var r1s = """
|
var r1s = """
|
||||||
proc $1(c: ptr gtk.Widget00; p: pointer) {.cdecl.} =
|
proc $1(c: ptr gtk.Widget00; p: pointer) {.cdecl.} =
|
||||||
let a = cast[$3](p) # OK for refs and maybe basic types like int, but wrong for string
|
when $3 is ref:
|
||||||
|
let a = cast[$3](p)
|
||||||
|
else:
|
||||||
|
let a = cast[ref $3](p)
|
||||||
let h: pointer = g_object_get_qdata(c, Quark)
|
let h: pointer = g_object_get_qdata(c, Quark)
|
||||||
assert(h != nil)
|
assert(h != nil)
|
||||||
let cn: gtk.Container = cast[gtk.Container](h)
|
let cn: gtk.Container = cast[gtk.Container](h)
|
||||||
$2(cn, a)
|
when $3 is ref:
|
||||||
|
$2(cn, a)
|
||||||
|
else:
|
||||||
|
$2(cn, a[])
|
||||||
""" % [$procNameCdecl, $p, ats]
|
""" % [$procNameCdecl, $p, ats]
|
||||||
|
|
||||||
let r2s ="""
|
let r2s ="""
|
||||||
|
|
@ -433,15 +439,15 @@ proc $1(container: gtk.Container; a: $2) =
|
||||||
GC_ref(a)
|
GC_ref(a)
|
||||||
gtk_container_foreach(cast[ptr gtk.Container00](container.impl), $3, cast[pointer](a))
|
gtk_container_foreach(cast[ptr gtk.Container00](container.impl), $3, cast[pointer](a))
|
||||||
else:
|
else:
|
||||||
var ar: ref $2 # this branch has issues, as the Nim proc p expects a value type
|
var ar: ref $2
|
||||||
new(ar)
|
new(ar)
|
||||||
ar[] = a
|
ar[] = a
|
||||||
GC_ref(ar)
|
GC_ref(ar)
|
||||||
gtk_container_foreach(cast[ptr gtk.Container00](container.impl), $3, cast[pointer](ar))
|
gtk_container_foreach(cast[ptr gtk.Container00](container.impl), $3, cast[pointer](ar))
|
||||||
$1($5, $4)
|
$1($5, $4)
|
||||||
""" % [$procName, ats, $procNameCdecl, $arg, $container]
|
""" % [$procName, ats, $procNameCdecl, $arg, $container]
|
||||||
echo r1s
|
#echo r1s
|
||||||
echo r2s
|
#echo r2s
|
||||||
result = parseStmt(r1s & r2s)
|
result = parseStmt(r1s & r2s)
|
||||||
|
|
||||||
# 447 lines
|
# 453 lines
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue