lua-users home
lua-l archive

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


> On 28/12/2010 9.25, Dirk Laurie wrote:
> >How does one iterate over all the keys of a table _except_
> >the ones that ipairs would reach?
> 
> (slow and untested):
> 
> local skip = {}
> for i, _ in ipairs(t) do
>     skip[i] = true
> end
> for k, v in pairs(t) do
>     if not skip[k] do
>         -- something
>     end
> end

This solution is simple and elegant; as it uses 'ipairs' itself, it
avoids any problem of missinterpreting the way it works.  The complexity
of the code is the same of other proposals (linear with the size of the
table), so your "slow" here is quite relative.

-- Roberto