[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Generalized pairs, was Re: linking tables to C++ objects?
From: Rici Lake <lua () ricilake ! net>
Date: 2007-02-27 18:22:18
Message-ID: 4d9b0b12945d8d2bcdc7c14e93fcef7c () ricilake ! net
[Download RAW message or body]
On 27-Feb-07, at 12:22 PM, Mark Hamburg wrote:
> I agree that pairs should be changed to look for a __pairs metamethod.
> Doing
> so would resolve a number of problems with using proxy tables.
> (Interestingly, ipairs needs no such help...)
Yes, although in some cases one might want to assign ipairs as
the __pairs metamethod of a table :)
The code in the GeneralizedPairsAndIpairs module generalizes
pairs() and ipairs() in different ways; the pairs() implementation
looks for a __pairs metamethod, while the ipairs() implementation
simply uses lua_gettable() rather than lua_rawgeti(), allowing
the use of ipairs() with, for example, userdata which are indexed
with integer keys.
In practice, the generalization of ipairs() proved to be less
useful than I thought it would. In the vast majority of cases
where I would want ipairs() to honour __index metamethods, I
would also want it to be the implementation of __pairs().
What would, I think, be useful would be allowing the #
operator to respect a __len metamethod for a table, and
not just for non-table datatypes.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic