Use luajit table.clear properly

Fixes #25
This commit is contained in:
Max Cahill 2021-06-29 14:46:40 +10:00
parent a2c7800290
commit 1de942daa8

View File

@ -256,17 +256,22 @@ function tablex.dedupe(t)
return r return r
end end
--(might already exist depending on luajit) --(might already exist depending on environment)
if not tablex.clear then if not tablex.clear then
--remove all values from a table local imported
--useful when multiple references are being held --pull in from luajit if possible
--so you cannot just create a new table imported, tablex.clear = pcall(require, "table.clear")
function tablex.clear(t) if not imported then
assert:type(t, "table", "tablex.clear - t", 1) --remove all values from a table
local k = next(t) --useful when multiple references are being held
while k ~= nil do --so you cannot just create a new table
t[k] = nil function tablex.clear(t)
k = next(t) assert:type(t, "table", "tablex.clear - t", 1)
local k = next(t)
while k ~= nil do
t[k] = nil
k = next(t)
end
end end
end end
end end