lua-users home
lua-l archive

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


Dirk,

>> If __pairs is invoked wth a second argument equal to the special value
>> false, the caller is not interested in values (only in keys), so the
>> returned iterator may returned any value, including nil, or no value
>> at all, for them.
>
> You can already write "for k in pairs(tbl,false) do ... end".

Sure I can. However, certain kinds of (heavily meta) tables may have a
high cost of value retrieval, which this proposal aims to eliminate.

>> * Key-adjusting __newindex semantics.
>>
>> If __newindex is invoked with a special fourth argument (what kind of?
>> equal to false?), then the metamethod is expected (but not required)
>> to perform insertion (a la table.insert) if the vale is non-nil, or
>> removal (a la table.remove) if the value is nil. This may or may not
>> include:
>> - adjusting indices of other values;
>> - raising an error if adjustment is not possible (e.g. the key is a
>> string and already used) or there is no such element to remove;
>> - supporting nil as key;
>> - returning the (actual) key used.
>
> I can't figure out what the idea is. Give an example.
>

One simple use case is an alternate method of making
table.insert/table.remove meta-aware in a really general manner and
without resorting to the 5.3 sequence of __index/__newindex calls
which are slower while being too specific.

Best regards,

-- 
DoubleF