-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtbdumper.lua
39 lines (33 loc) · 1.09 KB
/
tbdumper.lua
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 _M = {_VERSION = '1.0'}
local mt = { __index = _M }
function _M.var_dump(data, max_level, prefix)
if type(prefix) ~= "string" then
prefix = ""
end
if type(data) ~= "table" then
print(prefix .. tostring(data))
else
print(data)
if max_level ~= 0 then
local prefix_next = prefix .. "\t"
print(prefix .. "{")
for k,v in pairs(data) do
io.stdout:write(prefix_next .. k .. " = ")
if type(v) ~= "table" or (type(max_level) == "number" and max_level <= 1) then
print(v)
else
if max_level == nil then
_M.var_dump(v, nil, prefix_next)
else
_M.var_dump(v, max_level - 1, prefix_next)
end
end
end
print(prefix .. "}")
end
end
end
function _M.print(data, max_level)
_M.var_dump(data, max_level or 10)
end
return setmetatable({ a=a, b=c }, mt)