I know switches are not great with sparse constant spaces such as when using
hashes (i.e. only a few tenths of used values from 2^32 possible values) but
I like the compiler doing the binary search for me (gcc does) instead of
having to figure it out myself. I'm also experimenting hashing the hash
(just shifts and xors, nothing fancy or costly) to make the space dense
enough so the switch will (hopefully) become a goto table + one if for each
case to see if it's really a match. Better than the hard-coded binary
tree...
If switch construction is what you need, I guess there are 2 ways:
1. Write a pointer->number hash and use it like
switch (lookup (L, lua_tostring (L, 1))) {
case 0:
case 1:
...
}
2. Write a patch to Lua yourself, put it somewhere into
http://lua-users.org/wiki/LuaDirectory
and maintain to keep it up-to-date.