lua-users home
lua-l archive

Re: Next Version of Lua?

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


> 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.

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