fortressforever-scripts/maps/includes/util/utils.lua
squeek 5a30b6255d Practicing what I preach: Removed all file-local variables from util/collection.lua
File local variables frustrated me to no end in the Don't Starve codebase; they have no real reason for existing and they only serve to limit mod-ability (their implementation would have to be copy+pasted for any other file to use it and the implementation can't be modified by other files), so they should be generally avoided.
2015-04-05 12:46:11 -07:00

34 lines
No EOL
622 B
Lua

function table.clear(tbl)
for k in pairs(tbl) do
tbl[k] = nil
end
end
function table.contains(tbl, element)
if tbl == nil then return false end
for _, value in pairs(tbl) do
if value == element then
return true
end
end
return false
end
function table.contains_any(tbl, elements)
if tbl == nil or elements == nil then return false end
for _, value in pairs(tbl) do
for _, element in pairs(elements) do
if value == element then
return true
end
end
end
return false
end
function totable(obj)
if obj == nil then return {} end
if type(obj) == "table" then return obj end
return {obj}
end