lua-users home
lua-l archive

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

It is interesting to note that, as always in Lua, there are plenty of
ways being used for the same purpose..
A consensus seems to build on the fact that enumeration values should
be represented as strings (or sometimes keys in a table argument).

This is probably better than defining global or module constants for
the following reasons :
 - We can check that the enumeration string is within a fixed set of values.
 - Enumerations do not pollute the namespace
 - That is the way Lua chose for the standard libraries
 - Memory is saved because enumeration values need only be stored in
static const C structures
 - In my projects at least, the Readline based completion can list
acceptable values for enum parameters

So, you can still choose from at least the following options:
 - Upper case, lower case, or case insensitive names
 - For multiple bitfields:
    - single concatenated string: "frontonly, backvideo"
    - a list of strings:  { "frontonly","backvideo" }
    - a table with string keys: { frontonly=true, backvideo=true }
    - variable number of parameters: "frontonly", "backvideo"