Re: Slight discrepency in the documentation for
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Slight discrepency in the documentation for
- From: Rici Lake <lua@...>
- Date: Wed, 7 Feb 2007 18:58:02 -0500
On 7-Feb-07, at 6:49 PM, Eric Raible wrote:
And obviously it could break things if one redefines "next"
inappropriately
(that's what I meant by "both the advantage and the disadvantage" in my
original post).
If you wanted that advantage, you should redefine pairs instead of (or
as well as) redefining next. Looking up next() in the globals table is
not the same as looking it up in the current function environment, and
that can get really confusing really fast.
Personally, I think that pairs() ought to look up a __pairs()
metamethod, using (the built-in) next() function as a default; I've
found that to be extremely useful. There's a sample implementation at
http://lua-users.org/wiki/GeneralizedPairsAndIpairs
I'm not as convinced by the ipairs implementation on that page as I was
when I first wrote, but I've left it there for historical reference.