-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
39 lines (36 loc) · 1.03 KB
/
utils.lua
File metadata and controls
39 lines (36 loc) · 1.03 KB
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
38
39
local utils = {}
function utils.dump(pTable, offset)
offset = offset or 1
local i = 1
for key, value in pairs(pTable) do
if type(value) == "table" then
print(string.rep("| ", offset - 1) .. "|-" .. tostring(key))
utils.dump(value, offset + 1)
else
local str = string.rep("| ", offset - 1)
if i == #pTable then
str = str .. ">-"
else
str = str .. "|-"
end
str = str .. tostring(key) .. "=" .. tostring(value)
print(str)
i = i + 1
end
end
end
function utils.deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[utils.deepcopy(orig_key)] = utils.deepcopy(orig_value)
end
setmetatable(copy, utils.deepcopy(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
return utils