Skip to content

Instantly share code, notes, and snippets.

@marvhus
Last active December 7, 2024 19:19
Show Gist options
  • Save marvhus/3706146fba65ef3c2d9d581ceea1eaf1 to your computer and use it in GitHub Desktop.
Save marvhus/3706146fba65ef3c2d9d581ceea1eaf1 to your computer and use it in GitHub Desktop.
Enum array in Jai
Player :: enum {
ONE;
TWO;
}
player_colors :: #run -> []Color {
colors: [#run enum_max_value(type_info(Player)) + 1]Color;
colors[Player.ONE] = .{1, 0, 0};
colors[Player.TWO] = .{0, 1, 0};
return colors;
};
Color :: struct {
r,g,b: u8;
}
main :: () {
print("%\n", player_colors);
print("%\n", type_of(player_colors));
}
enum_max_value :: (ti: Type_Info_Enum) -> int {
max: int;
for ti.values {
if it > max then max = it;
}
return max;
}
#import "Basic";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment