lua-users home
lua-l archive

Re: Iterator question

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


2013年6月12日 <meino.cramer@gmx.de>:
> is it possible (and how) to create an iterator with lua, which returns
> the [n]th _and_ the [n+1]th value of in array/table with each call?
It is trivial if you are willing to create a new closure each time.
function brix(a)
 local i,n=0,#a
 return function()
 i=i+1
 if i<n then return a[i],a[i+1] end
 end
end

AltStyle によって変換されたページ (->オリジナル) /