[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Feature Request, `__next` metamethod.
- From: "Soni L." <fakedme@...>
- Date: Fri, 24 Jun 2016 06:20:01 -0300
On 24/06/16 05:00 AM, Duane Leslie wrote:
next() is supposed to be raw. You should be using `local f, o, i =
pairs(obj)` and passing f, o and i around.
Would it be possible to add a `__next` metamethod to allow the `pairs`
behaviour to be inferred in the same way that now the `ipairs`
behaviour is inferred from the `__index` metamethod. I have looked
through some discussions of this in the mailing list in the past and
it seems to have been that the `__pairs` metamethod was preferred
because it was more powerful (it allows the construction of a `next`
equivalent function as a closure with additional information).
The problem I have is that I have situations where the `next()`
function makes more sense to iterate over some userdata objects than
using `for ... pairs` but I cannot make the behaviour of these two
The idea would be to have the situation where I could define just the
`__next` metamethod, and this would be used as the result of the call
to the `next` function, and so in turn would imply that `pairs` would
call my `__next` metamethod through the standard `next` function.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.