Closed RSDuck closed 6 years ago
Thanks for the suggestions. I'm quite a Nim noob, I think I was looking at some existing C bindings and copied what they've done. If you'd like to provide a pull request with these suggestions I'm happy to merge it :)
You annotated all of your structures with
bycopy
, but I haven't found a place where it would be needed. Leaving it out would allow the Nim compiler to just pass a pointer which is obviously much faster. The pass by pointer/pass by value is hidden, so the semantic doesn't change. It isn't allowed modify a nonvar
parameter anyway and if you assign a variable with the value of the parameter, all values are copied.The second thing is the proc
unsafeAddr
which can be used to retrive a pointer to a location of alet
or nonvar
parameter. This is very useful in situations where you can guarantee that the memory the pointer is pointing to won't be modified, like e.g. here https://github.com/floooh/sokol-nim/blob/master/sokol/gfx.nim#L591EDIT: also I would annotate the types instead with the pure pragma to ensure they are layed out as plain C structs