2011-08-28 23:32:24 +02:00
|
|
|
function table.dump(t, depth)
|
|
|
|
if not depth then depth = 0 end
|
|
|
|
for k,v in pairs(t) do
|
2011-12-07 01:31:55 +01:00
|
|
|
str = (' '):rep(depth * 2) .. k .. ': '
|
2011-08-28 23:32:24 +02:00
|
|
|
if type(v) ~= "table" then
|
2011-11-17 21:40:31 +01:00
|
|
|
print(str .. tostring(v))
|
2011-08-28 23:32:24 +02:00
|
|
|
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
|
|
|
|
|
2012-01-05 02:55:07 +01:00
|
|
|
function table.selectivecopy(t, keys)
|
2011-08-28 23:32:24 +02:00
|
|
|
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
|
2012-01-05 02:55:07 +01:00
|
|
|
|
|
|
|
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
|
2012-01-07 21:00:07 +01:00
|
|
|
table.remove(t, k)
|
2012-01-05 02:55:07 +01:00
|
|
|
end
|
|
|
|
end
|
2012-01-07 21:00:07 +01:00
|
|
|
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
|
2012-01-05 02:55:07 +01:00
|
|
|
end
|
2012-01-07 21:00:07 +01:00
|
|
|
return true
|
2012-01-05 02:55:07 +01:00
|
|
|
end
|