Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make better enums #8

Open
schveiguy opened this issue Aug 31, 2021 · 1 comment · May be fixed by #50
Open

Make better enums #8

schveiguy opened this issue Aug 31, 2021 · 1 comment · May be fixed by #50

Comments

@schveiguy
Copy link
Owner

All enums in raylib are super-verbose, owing to the fact that C doesn't do namespaces really. So things like KeyboardKey.KEY_A are painfully verbose.

It might make sense to make a raylibenum module that uses static compilation techniques to redefine the enums into a nicer enum system (e.g. Key.A) I'm picturing something like:

string makeBetterEnum(T)(string prefixToRemove, string newName)
{
   string result = "enum " ~ newName ~ " {\n";
   string withoutPrefix(string s) { ... }
   static foreach(m; __traits(allMembers, T))
      result ~= "    " ~ withoutPrefix(m) ~ " = " ~ __traits(getMember, T, m).to!string ~ ",\n";
   return result ~ "}\n";
}

mixin(makeBetterEnum!KeyboardKey("KEY_", "Key"));
@SpiceyWolf
Copy link

I like that idea... I cant really think of any more efficient ways to support cleaner syntax that doesnt screw with the generated changes or in some other way make life harder...

LiamM32 added a commit to LiamM32/raylib-d that referenced this issue Mar 27, 2024
LiamM32 added a commit to LiamM32/raylib-d that referenced this issue Mar 27, 2024
LiamM32 added a commit to LiamM32/raylib-d that referenced this issue Mar 27, 2024
@LiamM32 LiamM32 linked a pull request Mar 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants