I would be glad to hear some recommendations (2-cents sort of stuff) about the right approach when using a C++ library from Nim. I am not talking about the wrapping itself. I am more interested on what comes after.
For instance, I have the following from c2nim:
type
gp_Pnt* {.importcpp: "gp_Pnt", header: "gp_Pnt.hxx", bycopy.} = object
proc constructgp_Pnt*(Xp: Standard_Real; Yp: Standard_Real; Zp: Standard_Real): gp_Pnt {.
constructor, importcpp: "gp_Pnt(@)",header: "gp_Pnt.hxx".}
...
proc X*(this: gp_Pnt): Standard_Real {.noSideEffect, importcpp: "X", header: "gp_Pnt.hxx".}
that I can use from Nim like:
import gp_Pnt
let pnt = constructgp_Pnt( (1.0).Standard_Real,
(2.0).Standard_Real,
(3.0).Standard_Real)
let x = pnt.X().float
echo repr x
But in order to make it easier to use, I would do the following:
import gp_Pnt
proc Pnt(x,y,z:float):gp_Pnt =
constructgp_Pnt( x.Standard_Real, y.Standard_Real, z.Standard_Real)
proc x(pnt:gp_Pnt):float =
pnt.X.float
let pnt = Pnt( 1.0, 2.0,3.0)
echo pnt.x
Given that C++ is OOP, should I use methods or something?
Any advise is welcomed.
From my limited knowledge, OOP is just a programming paradigm. I've never wrapped a C++ library yet, just C, but I did follow along with a "neural networks from scratch" series where the other was coding everything with OOP. When I recreated his examples I just did it with the procedural style I'm accustomed to.
I'm sure as long as you understand how the code is working and what it's trying to do- you can use methods and write OOP or a completely different way and be fine. Plus, with the different ways you can call functions in Nim you can make it seem like OOP anyway:
stdin.readLine() vs readLine(stdin)
That's my 2 cents for whatever it's worth lol