Last active
December 7, 2024 19:19
-
-
Save marvhus/3706146fba65ef3c2d9d581ceea1eaf1 to your computer and use it in GitHub Desktop.
Enum array in Jai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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