You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1009 B
60 lines
1009 B
12 years ago
|
-- @docclass table
|
||
|
|
||
13 years ago
|
function table.dump(t, depth)
|
||
|
if not depth then depth = 0 end
|
||
|
for k,v in pairs(t) do
|
||
13 years ago
|
str = (' '):rep(depth * 2) .. k .. ': '
|
||
13 years ago
|
if type(v) ~= "table" then
|
||
13 years ago
|
print(str .. tostring(v))
|
||
13 years ago
|
else
|
||
|
print(str)
|
||
|
table.dump(v, depth+1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function table.copy(t)
|
||
|
local res = {}
|
||
|
for k,v in pairs(t) do
|
||
|
res[k] = v
|
||
|
end
|
||
|
return res
|
||
|
end
|
||
|
|
||
13 years ago
|
function table.selectivecopy(t, keys)
|
||
13 years ago
|
local res = { }
|
||
|
for i,v in ipairs(keys) do
|
||
|
res[v] = t[v]
|
||
|
end
|
||
|
return res
|
||
|
end
|
||
|
|
||
|
function table.merge(t, src)
|
||
|
for k,v in pairs(src) do
|
||
|
t[k] = v
|
||
|
end
|
||
|
end
|
||
13 years ago
|
|
||
|
function table.find(t, value)
|
||
|
for k,v in pairs(t) do
|
||
|
if v == value then return k end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function table.removevalue(t, value)
|
||
|
for k,v in pairs(t) do
|
||
|
if v == value then
|
||
13 years ago
|
table.remove(t, k)
|
||
12 years ago
|
break
|
||
13 years ago
|
end
|
||
|
end
|
||
13 years ago
|
end
|
||
|
|
||
|
function table.compare(t, other)
|
||
|
if #t ~= #other then return false end
|
||
|
for k,v in pairs(t) do
|
||
|
if v ~= other[k] then return false end
|
||
13 years ago
|
end
|
||
13 years ago
|
return true
|
||
13 years ago
|
end
|