[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Next Version of Lua?
- From: "John Hind" <john.hind@...>
- Date: Wed, 10 Jun 2009 13:19:22 +0100
I did not realise you could avoid the empty parentheses in this case,
however it is still a bodge since it precludes using "__call" for what it is
intended for. For example I have a "delegate_list" class which maintains a
list of callback functions. I use a call override to allow the object to act
as a true proxy for the functions. However this precludes also providing a
"self-iterator" and breaks the consistency of the library.
Surely it would be trivial to provide a second metamethod which worked just
like "__call" but only in the scope of the generic for statement?
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of Luiz Henrique de
> Figueiredo
> Sent: 10 June 2009 12:59
> To: Lua list
> Subject: Re: Next Version of Lua?
>
> > I'd vote for a '__iter' metamethod so you could provide a customised
> > iterator factory for an object class. This would allow syntax:
> >
> > for k,v in obj do ... end
>
> As you have noticed, you can use __call for that:
>
> t={10,20,name="hello",size=45}
>
> setmetatable(t,{
> __call = function (x,y,z) return next(x,z) end
> })
>
> for k,v in t do print(k,v) end
>
> No parentheses needed.