lua-users home
lua-l archive

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


Thomas Lauer yazmış:
I am currently writing a library that calls all sorts of external C/C++
functions: regexes, win32 stuff... Many of these functions use a slew of
numerical constants to describe their behaviour. Alas, defining such a
list of simple constants is not one of Lua's many strong points, if I
may say so.

I see three basic possibilities, all more or less ugly:

* trying to go down the string route. That won't work well as many of
the constants are to be or'ed together or will be used in (bitwise)

* define a list of globals like this:
FA_ARCHIVE=0x0020 FA_DEVICE=0x0040 FA_NORMAL=0x0080...

* define a table FA like this:

I have a gut feeling that the third option is the best of the lot but I
would like to know what others have done when faced with long lists of
constants. (A quick search in the archives has brought no revelation.)

Things I consider are first and foremost ease of use (for the clients of
the library, not for me;-) and efficiency, space- and time-wise.

I'm currently writing a Cairo binding. There, I used Cairo as namespace table, and put all enums by dropping CAIRO_ prefix as your third choice.

I think it is easier to use Cairo.PATH_MOVE_TO instead of Cairo.CAIRO_PATH_MOVE_TO.

Hakki Dogusan