mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
parent
a2c7800290
commit
1de942daa8
25
tablex.lua
25
tablex.lua
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user