lua-users home
lua-l archive

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



In my Lua application I have userdata objects with value semantics (position coordinates) that I sometimes want to use as table keys. I.e., I want table lookup based on equality rather than identity.
The only way I know for this, is making sure you only create _one_ userdata for each value combination (you should use a lookup in the creation function for that). Otherwise, if you end up having multiple userdata they aren't usable as table keys. Period. No way I know for changing that (think strings, and the way they are immutable; these are very profound Lua assumptions that in the end boil down to runtime efficiency).
Yes I've thought of this, but then I have the overhead of a lookup for every object creation and I need a garbage collection handler (to clear out unused values from the lookup structure). I'm not sure handling the rather unusual case of using positions as keys warrants slowing down the very common case of creating and destroying position objects.

// Niklas