Skip to content

Commit

Permalink
vardump uses serpent
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Apr 25, 2015
1 parent e34db1d commit c27a2e7
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions bot/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,42 +116,8 @@ function download_to_file(url, file_name)
return file_path
end


function vardump(value, depth, key)
local linePrefix = ""
local spaces = ""

if key ~= nil then
linePrefix = "["..key.."] = "
end

if depth == nil then
depth = 0
else
depth = depth + 1
for i=1, depth do spaces = spaces .. " " end
end

if type(value) == 'table' then
mTable = getmetatable(value)
if mTable == nil then
print(spaces ..linePrefix.."(table) ")
else
print(spaces .."(metatable) ")
value = mTable
end
for tableKey, tableValue in pairs(value) do
vardump(tableValue, depth, tableKey)
end
elseif type(value) == 'function' or
type(value) == 'thread' or
type(value) == 'userdata' or
value == nil
then
print(spaces..tostring(value))
else
print(spaces..linePrefix.."("..type(value)..") "..tostring(value))
end
function vardump(value)
print(serpent.block(value, {comment=false}))
end

-- taken from http://stackoverflow.com/a/11130774/3163199
Expand Down

0 comments on commit c27a2e7

Please sign in to comment.