[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Deleting all elements from a table
- From: "Aaron Brown" <arundelo@...>
- Date: Tue, 12 Sep 2006 18:28:54 -0400
Nick Gammon wrote:
I want to delete all elements from a table (any sort of
keys, not just numeric).
Is this OK?
t = { a = 1, b = 2, c = 3, 4 = 4}
for k in pairs (t) do
t [k] = nil
end -- for
Yes.
It *seems* to work however I seem to recall that you
aren't supposed to change keys during a table traversal
From the manual:
# The behavior of next is undefined if, during the
# traversal, you assign any value to a non-existent field in
# the table. You may however modify existing fields. In
# particular, you may clear existing fields.
--
Aaron