[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: hpairs?
- From: Drake Wilson <drake@...>
- Date: Tue, 28 Dec 2010 01:53:33 -0700
Quoth Dirk Laurie <dpl@sun.ac.za>, on 2010-12-28 10:25:22 +0200:
> How does one iterate over all the keys of a table _except_
> the ones that ipairs would reach?
You can't really win that one nicely; that division isn't set up to be
easily used.
I think you could do something like (untested):
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)
return k, v
end
return f2, s, k0
end
but I wouldn't, unless really needed. If you have a preceding
ipairs() sitting around you can just save the threshold that way.
---> Drake Wilson