lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> So I would like to know the community opinion on this: How to implement this kind of C enums?

In my Pipeline project, enumeration values are strings.
But you can OR bitfield values by just concatenating them with any
not-alphanumerical separator.
Moreover, the "~" character is used to denote AND NOT value

So for your enumeration (note that I have added ALL entry):
> typedef enum {
>     UNKNOWN    = 0x00000000,
>     FRONTONLY  = 0x00000001,
>     BACKVIDEO  = 0x00000002,
>     BACKSYSTEM = 0x00000004,
>     TRIPLE     = 0x00000008,
>     WINDOWS    = 0x00000010,
>     ALL  = 0x0000001F
> } BufferMode;

We can have for example:
 Fct ("FRONTONLY")  --> 1
 Fct ("BACKVIDEO, TRIPLE") --> 0x82
 Fct "BACKSYSTEM|WINDOWS" --> 0x14
 Fct ("ALL ~TRIPLE, ~FRONTONLY") --> 0x16