-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.lua
More file actions
37 lines (34 loc) · 772 Bytes
/
table.lua
File metadata and controls
37 lines (34 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function table.Copy( tbl )
local copy
if type( tbl ) == "table" then
copy = {}
for orig_key, orig_value in next, tbl, nil do
copy[ table.Copy( orig_key ) ] = table.Copy( orig_value )
end
setmetatable(copy, table.Copy( getmetatable( tbl ) ) )
else
copy = tbl
end
return copy
end
function table.ContainsValue( tbl, value )
for _, v in pairs( tbl ) do
if v == value then
return true
end
end
return false
end
function table.ContainsKey( tbl, key )
for k, v in pairs( tbl ) do
if k == key then
return true
end
end
return false
end
function table.Count( t )
local i = 0
for k in pairs( t ) do i = i + 1 end
return i
end