lua-users home
lua-l archive

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

Yes indeed - I contributed to that thread! The __call trick is one I have
used many times and it is fine until you do a delegate class and want both a
function call metamethod and a custom iterator for the same class!

I am puzzled as to why it is OK to drop the empty parenthesis when doing a
"pseudo" function call but not when doing a "real" method call?

The difficulties (but not showstoppers) of the __iter approach have been
addressed in the earlier thread, but the survival of the (IMHO pointless)
"__pairs" and "__ipairs" approach has not. These are just bloat and buy us
next to nothing: the alternatives available to anyone who wants these are
even easier than those available to the "__iter" camp!

> -----Original Message-----
> From: [mailto:lua-
>] On Behalf Of Luiz Henrique de
> Figueiredo
> Sent: 09 September 2009 12:03
> To: Lua list
> Subject: Re: Regarding the name 'pairs'
> > I would prefer a single __iter metamethod with deeper language
> integration
> > so we can write:
> >
> > for v in myobject do print(v) end
> You can do that already:
> > for v in myobject:myiterator do print(v) end
> This is a syntax error. These would work:
> 	for v in myobject:myiterator() do print(v) end
> 	for v in myobject.myiterator do print(v) end