forked from dodo/uzful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvardump.lua
57 lines (49 loc) · 1.34 KB
/
vardump.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--------------------------------------------------------------------------------
-- @author john
-- @copyright 2011 https://github.com/tuxcodejohn
-- @release v3.4-503-g4972a28
--------------------------------------------------------------------------------
--- Table dumping
-- @param data a table
-- @return stringified table
function vardump(data)
local function rvardump (rdata, erg,indent,key)
local linePrefix = ""
if key ~= nil then
linePrefix = string.format("[%s]",key)
end
if(indent == nil) then
indent = 0
else
indent = indent +1
table.insert(erg,string.rep(" ",indent))
end
if type(rdata) == 'table' then
mTable = getmetatable(rdata)
if mTable == nil then
table.insert(erg,linePrefix)
table.insert(erg ,"(table)")
else
table.insert(erg ,"(metatable)")
rdata = mTable
end
table.insert(erg,"\n")
for tableKey, tableValue in pairs(rdata) do
rvardump(tableValue, erg,indent,tableKey)
end
elseif type(rdata) == 'function' or
type(rdata) == 'thread' or
type(rdata) == 'userdata' or
rdata == nil then
table.insert(erg,tostring(rdata))
table.insert(erg,"\n")
else
table.insert(erg,string.format("%s(%s)%s",linePrefix,type(rdata),tostring(rdata)))
table.insert(erg,"\n")
end
end
local erg= {}
rvardump(data,erg)
return table.concat(erg)
end
return vardump