how to delete all elements in a Lua table?

后端 未结 5 842
长发绾君心
长发绾君心 2021-02-04 00:06

How do I delete all elements inside a Lua table? I don\'t want to do:

t = {}
table.insert(t, 1)
t = {}  -- this assigns a new pointer to t

I w

5条回答
  •  失恋的感觉
    2021-02-04 00:47

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

    Will also work - you may have difficulty with ipairs if the table isn't used as an array throughout.

提交回复
热议问题