-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutil.lua
More file actions
52 lines (46 loc) · 1.21 KB
/
util.lua
File metadata and controls
52 lines (46 loc) · 1.21 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
40
41
42
43
44
45
46
47
48
49
50
51
52
local exports = { }
local function dump(node, level)
if not level then level = 1 end
if type(node) == 'nil' then
return "null"
end
if type(node) == "string" then
return '"'..node..'"'
end
if type(node) == "number" then
return node
end
if type(node) == "boolean" or type(node) == "cdata" then
return tostring(node)
end
if type(node) == "function" then
return tostring(node)
end
local buff = { }
local dent = string.rep(" ", level)
local tput = table.insert
if #node == 0 and next(node, nil) then
tput(buff, "{")
local i_buff = { }
local p_buff = { }
for k,data in pairs(node) do
tput(buff, "\n"..dent..dump(k)..': '..dump(data, level + 1))
if next(node, k) then
tput(buff, ",")
end
end
tput(buff, "\n"..string.rep(" ", level - 1).."}")
else
tput(buff, "[")
for i,data in pairs(node) do
tput(buff, "\n"..dent..dump(data, level + 1))
if i ~= #node then
tput(buff, ",")
end
end
tput(buff, "\n"..string.rep(" ", level - 1).."]")
end
return table.concat(buff, "")
end
exports.dump = dump
return exports