[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Type Metatables for Table and Userdata - Powerpatch
- From: steve donovan <steve.j.donovan@...>
- Date: Fri, 7 Dec 2012 09:39:02 +0200
On Thu, Dec 6, 2012 at 10:04 PM, Andrew Starks <firstname.lastname@example.org> wrote:
> myobj:tier() do..." and accomplish the same thing, more clearly. (For that
> reason, I like the idea of writing explicit iterators, rather than
> redefining ipairs/pairs, but I'm probably in the minority on that one)
I personally use this approach because often I just want to iterate
over all the objects in a 'collection' (doesn't necessarily have to be
a table!). Penlight's List class has a iter() method for this
Did play with making these lists callable to restore 'for obj in list'
but it's a very suboptimal solution - the list ends up carrying
iterator state. Easy to confuse, and confusing. So an __iter
metamethod does feel like a useful thing to have, although as Andrew
says, the for-statement becomes significantly harder to understand.
We do like to keep magic to a minimum...