[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: hpairs?
- From: Alexander Gladysh <agladysh@...>
- Date: Tue, 28 Dec 2010 12:18:47 +0300
On Tue, Dec 28, 2010 at 11:53, Drake Wilson <drake@begriffli.ch> wrote:
> Quoth Dirk Laurie <dpl@sun.ac.za>, on 2010-12-28 10:25:22 +0200:
> function hpairs(t)
> local f, s, k0 = pairs(t)
> local n = 1
> while t[n+1] ~= nil do n = n+1 end
>
> local function f2(s, k)
> local v
> repeat k, v = f(s, k) until not(type(k) == 'number' and 1 <= k and k <= n)
You should test k for being integer here.
This may (or may not) be interesting as well:
https://github.com/lua-nucleo/lua-nucleo/blob/master/lua-nucleo/tstr.lua#L56
> return k, v
> end
> return f2, s, k0
> end
Alexander.