Skip to content

Make better enums #8

@schveiguy

Description

@schveiguy

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"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions