[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Next Version of Lua?
- From: Peter Cawley <lua@...>
- Date: Wed, 10 Jun 2009 13:49:01 +0100
On Wed, Jun 10, 2009 at 1:38 PM, steve donovan<steve.j.donovan@gmail.com> wrote:
> On Wed, Jun 10, 2009 at 1:59 PM, Luiz Henrique de
> Figueiredo<lhf@tecgraf.puc-rio.br> > > 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.
>
> That is actually rather cute, but how would you do that for an
> ipairs-style iterator?
Or, alternatively, using the undocumented behaviour of ipairs:
ipairs_next = ipairs{}
t = {"hello", "world", "from", "Lua"}
setmetatable(t, {__call = function(t,_,i) return ipairs_next(t, i or 0) end})
for k, v in t do print(k, v) end