-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreeprinttb.lua
More file actions
52 lines (48 loc) · 1.22 KB
/
Copy pathtreeprinttb.lua
File metadata and controls
52 lines (48 loc) · 1.22 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
--Desc: 树形打印lua table表
local print = print
local tconcat = table.concat
local tinsert = table.insert
local srep = string.rep
local type = type
local pairs = pairs
local tostring = tostring
local next = next
function print_lua_table (lua_table, indent)
if not lua_table or type(lua_table) ~= "table" then
return;
end
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print(formatting)
print_lua_table(v, indent + 1)
print(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print(formatting..szValue..",")
end
end
end
local tbdata={
a="11",
b="22",
c={33,44,55},
d=66,
e={["g"]=77,["h"]="99",["j"]={1,3,4}},
f="10"
}
print_lua_table(tbdata)