Re: Modifying a table while iterating over it?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Modifying a table while iterating over it?
- From: Philippe Lhoste <PhiLho@...>
- Date: 2005年9月23日 09:09:41 +0200
Cory Bloyd wrote:
for key, value in pairs(someTable) do
if someArbitraryCondition() then
someTable[newKey()] = newValue()
end
end
If you are not short in memory, you can iterate on someTable and copy
existing keys and creating new keys in a new table. Then replace
someTable with newTable and you are safe.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --