lua-users home
lua-l archive

Re: Iterating pairs of keys from a table

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


2017年03月02日 12:09 GMT+02:00 Tim Hill <drtimhill@gmail.com>:
>
>> On Feb 28, 2017, at 9:43 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> If you must have an iterator factory, and wish to avoid a coroutine
>> (damn! I so seldom have good reason to use one, your problem
>> seemed to be a case in point), it is possible to do it all in a single
>> generic `for` by making your routine stateless. Exercise for the
>> reader.
>>
>> keypairs = function(tbl)
>> return function(tbl,k1,k2)
>> -- no upvalues required
>> return k1,k2
>> end
>> end
>>
>
> Well, you have me beaten. For a start, I was under the impression
> Lua only passed two arguments to the iterator function, yet you have
> three? Clearly I’m missing something.
You're right. I did not reread the manual page just before posting
the above. Should have done. Great! It does need a coroutine
after all!

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