lua-users home
lua-l archive

Re: Modifying a table while iterating over it?

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


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
-- -- -- -- -- -- -- -- -- -- -- -- -- --

AltStyle によって変換されたページ (->オリジナル) /