[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.copy
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 26 Jun 2003 14:23:07 -0300
>I'v found another useful function, IMHO worthy including in the library:
>
>function table.find(t, value)
> for k,v in t do
> if v == value then return k end
> end
>end
If you're going to need this often, then a much better solution is to
invert the table:
function table.invert(t)
local s={}
for k,v in t do s[v]=k end
return s
end
Then, instead of table.find(t,v), use s[v], where s=table.invert(t).
--lhf