floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
372 stars 49 forks source link

Conclusions? #1

Closed jacereda closed 5 years ago

jacereda commented 5 years ago

Can you share your conclusions so far? Is there anything you miss in zig? Why did you need those conv_xxx() adapter functions?

I'm considering starting a project using vulkan and I guess I'll face similar problems...

floooh commented 5 years ago

Hi, I'm currently waiting on this bug to be resolved (only seems to happen on macOS though): https://github.com/ziglang/zig/issues/3211

The reason why I duplicated some structs in the Zig module manually, along with those conv_ functions is mainly that I want the Zig wrapper module feel like it's been written in Zig from the outside. That means it should not expose any C types to the module user (like C strings or C function pointers), only "native" Zig types . So structs which use such C types need a Zig 'mirror struct', and a conversion function which converts C types to Zig types (another reason is that imported C structs are not automatically zero-initialized, so I do that in the mirror Zig struct... but that could also be implemented in Zig's C 'importer').

So in conclusion: the reason why there's a "manually augmented" Zig module instead of directly exposing the automatically imported C interface to the user is that I want the user API to feel like using a native Zig module, not an imported C module :)

jacereda commented 5 years ago

Got it, thanks.