lua-users home
lua-l archive

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


--- 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.