Last active
March 18, 2017 01:19
-
-
Save rm-code/b7fd78bbcc290f78db14 to your computer and use it in GitHub Desktop.
Debug function which dumps a table with a pretty structure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function serialize( value, output, depth ) | |
local ws = ' '; | |
for _ = 1, depth do | |
ws = ws .. ' '; | |
end | |
if type( value ) == 'table' then | |
for k, v in pairs(value) do | |
if type( v ) == 'table' then | |
table.insert( output, string.format( '%s[\'%s\'] = {', ws, tostring( k ))); | |
serialize( v, output, depth + 1 ); | |
table.insert( output, string.format( '%s},', ws )); | |
elseif type( v ) == 'string' then | |
table.insert( output, string.format( '%s[\'%s\'] = "%s",', ws, tostring( k ), tostring( v ))); | |
else | |
table.insert( output, string.format( '%s[\'%s\'] = %s,', ws, tostring( k ), tostring( v ))); | |
end | |
end | |
else | |
table.insert( output, string.format( '%s%s,', tostring( value ))); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment