[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua binding: How to implement C enum
- From: Ezequiel García <elezegarcia@...>
- Date: Thu, 15 Dec 2011 14:09:46 -0800 (PST)
--- El jue 15-dic-11, Patrick Rapin <toupie300@gmail.com> escribió:
>
> 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
Personally, this seems to me like a nice approach.
As already pointed out, It is *better* than simple numeric mapping because:
1. Can check valid values.
2. Don't pollute namespace, don't use lua variables.
3. Still seems to be easy to use.
One could even do this:
mode = 'BACKSYSTEM'
mode = mode .. '|BACKVIDEO'
On the other hand, it is *worse* than simple numeric mapping
because of all the string parsing this implies, just to
ORing some constants. Knowing that 'premature optimization
is the root of all evil',
am I being too paranoid here? (as usual)
Thanks everyone for all your answers :)
Ezequiel.