Re: __pairs metamethod - is it in?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: __pairs metamethod - is it in?
- From: David Jones <drj@...>
- Date: Mon, 7 Feb 2005 13:44:40 +0000
On Feb 07, 2005, at 11:44, Steve Donovan wrote:
asko.kauppi@sci.fi 02/07/05 12:32PM >>>
Why so complicated?
pairs = function( t )
local mt = getmetatable( t )
return ( ( mt and mt.__pairs ) or raw_pairs )( t )
end
It would be very cool if 'for i,v in t do...'
would use the global pairs() function; that would
(a) make quite explicit what the for-loop means
if t isn't an iterator function and (b) make interesting
overloading possible, such as above.
Well, it uses the global next() function, isn't that kind of good
enough? Try [[next = nil for i,v in t do ... ]]. It's also
deprecated.
I asked for these two facts to be documented ages ago (close to when
5.0 came out?).
David Jones