lua-users home
lua-l archive

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


> AFAIK, any keys present in a table constructor have to be immediate
> values. At any other place, you can use any expression you like to
> access tables (aside from some exceptions, such as nil, or keywords or
> symbols as names when using the dot notation).

you could also make use of __index to evaluate expressions as if there
were such keys in the table.  For example:

t = {
  __index = function(t, k) if(k < 100) then return true end end
}
setmetatable(t, t)
print(t[50])
> true
print(t[121])
> nil


It's a silly example but shows how an expression could cover the set
of keys in a table.

wes