lua-users home
lua-l archive

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


On 26/06/2011 09:55, HyperHacker wrote:
On Sun, Jun 26, 2011 at 01:11, Lorenzo Donati
<lorenzodonatibz@interfree.it>  wrote:
Mmmmh, maybe mine it's weird thinking, but...:
since the hash algorithm is a Lua internal, and so unspecified, its
calculations could depend on the specific platforms Lua is compiled on (if
it relies on some standard C platform-dependent feature).

So if you embed in Lua source (which is cross-platform) an hash pre-computed
on a platform and run the code on a different platform you could get a
broken program!

More weirdness, I don't know if could be sane, but the hashing could even
depend on the specific run on a specific machine. I don't know Lua internals
very much, but the hashing algo could also take some address into account,
so the hashes could change according to the current memory layout of the
machine you the interpreter.

If my ramblings are completely wrong, someone please correct me!

-- Lorenzo



I'm willing to bet that the hashes probably don't involve anything
machine-specific, but from a cleanliness standpoint, you shouldn't
rely on anything undocumented. In other words, since the hashing
algorithm isn't described in the manual, you shouldn't assume anything
about it, including even seemingly safe assumptions like the hashes
won't depend on the machine. Even if it's true now, being undocumented
means it could change later, or in a different implementation.

That's what I'm asking for, that the hash is available via a documented API function.

The use case here is scripting on videogame consoles where every byte and every cycle counts (so why compute a hash if one is already available?), but I think it could be used everywhere when there's a need to compare in C a string coming from Lua. Yes, hash collisions happen but it's something I already have to deal with.

Regarding the internal hash implementation changing, well, changes that break compatibility are bound to happen from time to time. It's just a matter of letting everyone know so they can update their code.

Cheers,

Andre