4 ms·
Lua tables accept arbitrary objects as keys, and make a difference between `foo[1]` and `foo["1"]`. Plus all the metatables goodies: weak key and/or value refe
by pygy_ 11y ago
Lua tables accept arbitrary objects as keys, and make a difference between `foo[1]` and `foo["1"]`.
Plus all the metatables goodies: weak key and/or value references, prototype inheritance, ...
- jschwartzi 11y agoThey even mark the difference to the degree that foo[1] is stored in a special "array part" of the table, while foo["1"] ends up in the hash part. Predictably, the array part uses less memory.
- thaumasiotes 11y ago> Lua tables accept arbitrary objects as keys, and make a difference between `foo[1]` and `foo["1"]`. That sounds... completely normal? Python dictionaries will do that too. So will Java HashMaps.
- sirclueless 11y agoThat comment was responding to a comment about PHP and JS, both of which do not make such a distinction.
- seabee 11y agoThere is another subtlety that values associated with integer keys are stored as an array. dicts and HashMaps don't do this.
- adrusi 11y agoAnd not even all integer keys! Lua will efficiently handle sparse arrays using tables.