I keep on playing with C++ bindings. For the following C++ constructor:
++
gp_Pnt(const gp_XYZ& Coord);
I was wondering about the & symbol. If I understand well, this means that Coord would be passed by reference. Am I right?
I have doubts about how it should be managed when wrapped. Should I use byref when wrapping the type gp_XYZ? Should I add do something like...
proc constructor_gp_Pnt*(Coordinates: ref gp_XYZ): gp_Pnt {.constructor,importcpp: "gp_Pnt(@)".}
Maybe nothing? I have checked that c2nim makes:
proc constructgp_Pnt*(Coord: gp_XYZ): gp_Pnt {.constructor, importcpp: "gp_Pnt(@)",
header: "gp_Pnt.hxx".}
Regards
“ref” specifically means a reference/pointer to a tracked (GC'd) heap object. That's not what “&” means in C++.
If a C++ parameter is a const reference, that’s equivalent to Nim's regular parameter passing of objects. (Primitives are passed by value; I don’t know if there’s a way to pass one by reference without making it mutable. It’s also possible to declare an object as pass-by-copy using a pragma.)
If a C++ parameter is a non-const reference, that’s equivalent to a “var” parameter in Nim.
Should I use byref when wrapping the type gp_XYZ?
I think so. Note that byref has nothing to do with ref.