lua-users home
lua-l archive

Re: Clearing tables

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


Wim Couwenberg wrote:
Tobias Käs wrote:
Is there an efficient way to remove all key/value pairs from a table?
Here's how I do it. Seems to work just fine:
function zap(table)
 local next = next
 local k = next(table)
 while k do
 table[k] = nil
 k = next(table)
 end
end
This is probably more efficient in lua 5.0 (untested), and at
the very least rather simpler:
function zap(table)
 for k in table do
 table[k] = nil
 end
end
--Adam
--
Adam D. Moss . ,,^^ adam@gimp.org http://www.foxbox.org/ co:3
Bereaved relatives are not amused
As on their dear departed I feverishly consume

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