zglfw icon indicating copy to clipboard operation
zglfw copied to clipboard

Fix for zig master

Open Sirius902 opened this issue 3 years ago • 2 comments

Currently zglfw doesn't compile on zig master because enums do not support extern anymore and unused variables are compile errors.

Sirius902 avatar Jun 27 '21 00:06 Sirius902

Okay so I've just realized there are some repeat enum values which prevents compilation, if anyone has suggestions on what to do I'll be happy to implement it to this PR.

Edit: From my inquires in on the zig discord it seems we'll have to remove the duplicate enum values. Another option (that is now used by translate-c) is to change the extern enums with duplicates to a struct with public constants in it.

Sirius902 avatar Jun 27 '21 19:06 Sirius902

Looks like the new way of translating C enums is to Zig is to create constant c_int's. (reference: https://github.com/ziglang/zig/issues/2115#issuecomment-827968279)

My opinion is to do it like this:

pub const Key = c_int;
pub const Unknown: Key = -1;
pub const Space: Key = 32;
pub const Apostrophe: Key = 39;
// ...
pub const Menu: Key = 348;
pub const Last: Key = Menu;

and functions that currently use the Key enum would still look like:

pub fn getKey(window: ?*Window, key: Key) KeyState {
    // ...
}

just without the @intToEnum and @enumToInt stuff.

For consistency, all enums should be converted to these c_int constants.

AlexJMohr avatar Aug 09 '21 00:08 AlexJMohr

@AlexJMohr Suggestion taken, pushed to update to Zig master

IridescentRose avatar Oct 20 '22 04:10 IridescentRose