# assume we have a library with a few functions like
proc t1(x: var uint32; y: var uint32) =
echo x, y
inc(x)
inc(y)
# one way to wrap these to Nim is this:
proc t2(x: var int; y: var int) =
var h1 = uint32(x)
var h2 = uint32(y)
t1(h1, h2)
x = int(h1)
y = int(h2)
I assume there is no better solution available? The GTK related modules seems to have a few hundred procs like that, so I think I have to write some generator code for that.
Sorry, I don't understand your reply.
Assume we have the low level proc
proc gtk_widget_get_preferred_height*(self: ptr Widget00; minimumHeight: var int32; naturalHeight: var int32) {.
importc: "gtk_widget_get_preferred_height", libprag.}
with two var parameters -- well int32 here, but it may be any other non standard Nim type like uint or cfloat.
And people may want Nim's int type.
What I already have for my higher level wrapper is something like a proc like
proc getPreferredHeight*(self: Widget; minimumHeight: var int32; naturalHeight: var int32)
Here self is a Nim proxy object, which contains the low level GTK widget, enabling garbage collection and all that. But still we have to wrap the int32 types, because the (non existent) users may want to pass plain ints. The question was, should I do it like pointed out in my initial post, or if there is a better solution. I think converters do not help for this case, and indeed my wrapper does contain no converters at all until now, and I want to keep that state, converters increase compile time, Araq does not like them too much. It may still be possible to do the conversion with a Nim macro, maybe by manipulating the AST. But is there a real advantage? I don't think so. So I think I will do it like indicated in the initial posing.
Oh, I see. Thanks for explanation.
How about change the approach for writing the wrapper? So instead of changing the supplied value, the procs return value so users would immediately know the return type.
However I do understand, it's easier for people who already knows GTK can immediately use your wrapper if the wrapper is about same with the original proc.