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
|
||||
end
|
||||
|
||||
--(might already exist depending on luajit)
|
||||
--(might already exist depending on environment)
|
||||
if not tablex.clear then
|
||||
--remove all values from a table
|
||||
--useful when multiple references are being held
|
||||
--so you cannot just create a new table
|
||||
function tablex.clear(t)
|
||||
assert:type(t, "table", "tablex.clear - t", 1)
|
||||
local k = next(t)
|
||||
while k ~= nil do
|
||||
t[k] = nil
|
||||
k = next(t)
|
||||
local imported
|
||||
--pull in from luajit if possible
|
||||
imported, tablex.clear = pcall(require, "table.clear")
|
||||
if not imported then
|
||||
--remove all values from a table
|
||||
--useful when multiple references are being held
|
||||
--so you cannot just create a new table
|
||||
function tablex.clear(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
|
||||
|
Loading…
Reference in New Issue
Block a user