lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Mon, 14 Sep 2009 10:34:36 -0400
Patrick Donnelly <> wrote:
> pairs and ipairs would still be useful with this __iter metamethod as
> tables have no __iter metamethod by default (naturally). We can also
> set the __iter metamethod of our metatables to next or (ipairs{}) to
> alleviate the need for calling pairs or ipairs manually.

This requires the object to be used as the state invariant for the
iterator function. This may not always be the case and would require
objects that need to use a different value for state to use a
non-standard iterator. The point of a metamethod is to increase use of
standard protocols. If the metamethod has the same form as "pairs" then
it works in all cases. I don't think the extra function call is too high
a price.

-- tom