lua-users home
lua-l archive

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

On Wed, Jun 10, 2009 at 2:49 PM, Peter Cawley<> wrote:
> 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

Very elegant - actually, it is documented that the ipairs() function
would return 'an iterator function' as its first result.