lua-users home
lua-l archive

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


Am 06.12.2013 00:12 schröbte William Ahern:
On Wed, Dec 04, 2013 at 06:04:43PM -0500, Marc Lepage wrote:
http://www.lua.org/source/5.1/lbaselib.c.html#luaB_collectgarbage

[...]

There are other problems with luaL_checkoption, though.

* [...]

* Enumerations sometimes have gaps, but there's no way to easily specify
   gaps, especially when a set is particularly sparse. I can only use
   luaL_checkoption a fraction of the time I need to map strings to integer
   values.

Use a NULL-terminated string array and `luaL_checkoption` to map a string to an index, and use another array to map the index to your enum value (like in the linked example). This way it doesn't matter how sparse your enums are ...

Philipp