lua-users home
lua-l archive

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


>I love the idea of tag methods for get/set. What I don't love is all the
>string processing required in the host environment to use them in a way
>where I want to match the key name against a set of known key names.

What string processing? The only time a string is processed in the core of Lua
is when it enters it; a hash value is computed by scanning the string. After
that, everything is done using this hash value. Hash lookups are supposed to be
O(1). A lot of effort goes to make sure that these lookups are fast. Having
fast tables is an implementation goal of Lua. Lua programmers should take
this for granted and not be afraid of "hidden" costs.

>FieldNameX = 1
>table[FieldNameX] = x

This is likely to be *slower* than table.FieldNameX = x when FieldNameX
is a global instead of a string: there will be 2 lookups: one to get the
value of FieldNameX and another to set the value of table[FieldNameX].
--lhf