Zig NEWS

Discussion on: Porting my game to the web

Collapse
 
kristoff profile image
Loris Cro • Edited

That's an amazing write up, thanks for sharing!

WRT the point about ifdefs, I think that the solution of putting all target-related constants into a single struct definition could be interesting as it allows for the same kind of grouping as ifdefs.

const target = switch (build_target) {
    .wasm => struct {
        pub const VERTEX_BASE_FILE = @embedFile("foo");
        pub const FRAGMENT_ALPHA_FILE = @embedFile("bar");
    },
    .win => struct {
        pub const VERTEX_BASE_FILE = @embedFile("fux");
        pub const FRAGMENT_ALPHA_FILE = @embedFile("bux");
    },
};

Enter fullscreen mode Exit fullscreen mode
Collapse
 
chapliboy profile image
Samarth Hattangady

Thanks =).

That can be something that I can try out. But I think that would mean that I would have to separate out the common constants from the platform-specific constants? Maybe something I could look into.