Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wipe or reset a table in Lua

How would I go about completely wiping or resetting a table in Lua. I want to make it into a blank table in the end.

like image 365
Josh Avatar asked Sep 03 '25 01:09

Josh


2 Answers

You iterate over the keys and make them nil.

for k,v in pairs(t) do
  t[k] = nil
end

If it's an array then remove values with table.remove()

like image 183
SpliFF Avatar answered Sep 06 '25 11:09

SpliFF


What about this way?

t = {..some non-empty table..}
...some code...
t={}
like image 21
Archinamon Avatar answered Sep 06 '25 12:09

Archinamon