You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm attempting to use my 3D-API wrapper sokol_gfx.h from zig, I got pretty far (importing the C header works, linking with the C implementation source also works), but now I'm hitting a snag when trying to setup 'option-bag structs' that are handed to the sokol_gfx API.
It looks like zig requires that all struct members must be initialized when the struct is 'instantiated', sokol_gfx uses an 'option bag philosophy': non-initialized struct members are assumed to be zero-initialized, which for sokol-gfx indicates that default-values are to be used for such fields. This works nicely with C99-style designated initialization, which sets missing fields to zero.
Currently zig complains about all missing struct members in the imported C structs, and in my case, providing an initialization for all struct members manually to 0 wouldn't make sense, the sokol_gfx API would be unusable.
Is there a simple solution to this problem which I missed? Maybe an option for the "@Cinclude()" process?
Also, what's zig's 'best practice' for such 'option-bag' APIs when written in pure zig? As far as I have seen, struct members cannot be assigned a default value, and all members must be initialized, but this gets a bit ugly if there are more than a handful members.
The text was updated successfully, but these errors were encountered:
I'll play around with it and see how it feels. Maybe it makes sense to write a small zig wrapper module for sokol_gfx which hides things like the std.mem.set... Thanks for the quick response :)
Did you (Andre) have any luck wrapping this with something that preserves the nice declarative flow of the original? I'm wondering whether this might be another motivating use case for #485
Hi, I'm attempting to use my 3D-API wrapper sokol_gfx.h from zig, I got pretty far (importing the C header works, linking with the C implementation source also works), but now I'm hitting a snag when trying to setup 'option-bag structs' that are handed to the sokol_gfx API.
It looks like zig requires that all struct members must be initialized when the struct is 'instantiated', sokol_gfx uses an 'option bag philosophy': non-initialized struct members are assumed to be zero-initialized, which for sokol-gfx indicates that default-values are to be used for such fields. This works nicely with C99-style designated initialization, which sets missing fields to zero.
For instance there are structs like sg_pipeline_desc, which all in all have dozens of members (in embedded structs): https://github.com/floooh/sokol/blob/a3057b13ba38d2d554a7f04e063f6550b2cc8bcb/sokol_gfx.h#L1422
Usually, only a small number of sg_pipeline_desc members are initialized, for instance:
Currently zig complains about all missing struct members in the imported C structs, and in my case, providing an initialization for all struct members manually to 0 wouldn't make sense, the sokol_gfx API would be unusable.
Is there a simple solution to this problem which I missed? Maybe an option for the "@Cinclude()" process?
Also, what's zig's 'best practice' for such 'option-bag' APIs when written in pure zig? As far as I have seen, struct members cannot be assigned a default value, and all members must be initialized, but this gets a bit ugly if there are more than a handful members.
The text was updated successfully, but these errors were encountered: