mirror of
https://github.com/fortressforever/fortressforever-scripts.git
synced 2025-02-11 22:57:38 +00:00
Add some misc table util functions
This commit is contained in:
parent
e8c59ff5ec
commit
3a63082b07
2 changed files with 29 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
-- Do not change this file.
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
require "util.utils"
|
||||
Class = require "util.class"
|
||||
Collection = require "util.collection"
|
||||
|
||||
|
|
28
maps/includes/util/utils.lua
Normal file
28
maps/includes/util/utils.lua
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
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
|
Loading…
Reference in a new issue