lua-users home
lua-l archive

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


Hi All,

When __index and __newindex are implemented in C, one has to compare the key with a list of strings to find out what key was passed in. I usually have all strings I need to compare fed to gperf, and use gperf to translate the string to an integer which then I can put in a switch for example. But gperf has to compute the hash of the string and ultimately compare the string to avoid false positives.
If key hashes are available to these metamethods, I can get rid of gperf 
and string by string comparisons. If the hash function is good enough, I 
can even live without one single string comparison, relying only on the 
hash.
For this to be possible, I'd also need easy access to Lua's hashes to 
pre-hash my strings and use the resulting hash in my code.
It would also be interesting to be able to override the default hashes.

So what I'd like to know is:

1. Is it possible to change __index and __newindex to receive the hash of the key?
2. Is it possible to expose Lua's hash functions to user code?
3. Is it possible to change Lua's hash functions to allow for experimentation with different hashes?
I know all three can be done by changing Lua, but I'd rather have them 
inside the core.
1 and 2 doesn't affect code performance (ok, in 1 an extra parameter 
must be pushed on the stack...) 3 might affect performance a little 
since hash functions would be calls to function pointers, unless it's a 
compile time feature.
Cheers,

Andre