[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: finding out number of records in a table??
- From: "Paul Hudson" <phudson@...>
- Date: Wed, 13 Sep 2006 07:05:31 +0100
>True enough. :) I missed your point, but now I think the main issue here is
>that for tables, if table[key] ~= nil, key/value access metamethods
(__index
>and __newindex) are not called; this would have to change with a new
>__removeindex, and, if so, why not simply use __newindex?
Because the pre-conditions are different, which would pointlessly (in my
view) complicate the code, and metamethods should run fast.
Now, __newindex is called if and only if the key does not exist in the
table.
__removeindex would be called if and only if the key did exist and was being
set to null.
Re-using __newindex instead would mean if the value was nil, the key was
being removed - or would it? What about an as-yet-non-existent key that was
being set to nil, and so not in fact to be added?
Adding __removeindex seems clearer and cleaner.
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.3/446 - Release Date: 12/09/2006