lua-users home
lua-l archive

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


On Thursday 24 June 2004 07:51, Virgil Smith wrote:

> Hmm, the above statements reminded me of something.
> Perhaps neither camp is 100% right or 100% wrong.  In fact maybe they are
> both exactly 50% right and 50% wrong.
>
> A __gettable metamethod is not useful to implementing "properties".  After
> all if you already have a value for the property then there is no need to
> generate the value via a handler function AND whatever value is stored "in
> the property location" is not really the property's value anyway because it
> might not be what is returned from the function.  __index on the other hand
> allows both property "get" handlers AND lazy evaluation / caching schemes.

It seems wrong to me to consider a language feature in the context of a 
specific application feature like "properties". Metamethods do not exist for 
the purpose of allowing the programmer to implement a specific feature like 
"properties" but rather to allow the execution of arbitrary code when an 
operation is performed on a table.  I'm just saying that it seems more 
logical to me that the basic operations of getting and setting a value in the 
table should be chosen instead of the specialized operations of getting and 
setting non-existing values. It just seems natural to me that, since the case 
where a non-existing value is read or written to is more specific than 
reading and writing any value, I should have to write extra code fore the 
first case and not the second.

-- Dimitris