You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
876 B
33 lines
876 B
-- Source: https://gist.github.com/lunixbochs/5b0bb27861a396ab7a86#file-var_dump-lua-L1 |
|
|
|
local function string(o) |
|
return '"' .. tostring(o) .. '"' |
|
end |
|
|
|
local function recurse(o, indent) |
|
if indent == nil then indent = '' end |
|
local indent2 = indent .. ' ' |
|
if type(o) == 'table' then |
|
local s = indent .. '{' .. '\n' |
|
local first = true |
|
for k,v in pairs(o) do |
|
if first == false then s = s .. ', \n' end |
|
if type(k) ~= 'number' then k = string(k) end |
|
s = s .. indent2 .. '[' .. k .. '] = ' .. recurse(v, indent2) |
|
first = false |
|
end |
|
return s .. '\n' .. indent .. '}' |
|
else |
|
return string(o) |
|
end |
|
end |
|
|
|
local function var_dump(...) |
|
local args = {...} |
|
if #args > 1 then |
|
var_dump(args) |
|
else |
|
print(recurse(args[1])) |
|
end |
|
end |
|
return var_dump
|
|
|