Skip to content

Instantly share code, notes, and snippets.

@rm-code
Last active March 18, 2017 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rm-code/b7fd78bbcc290f78db14 to your computer and use it in GitHub Desktop.
Save rm-code/b7fd78bbcc290f78db14 to your computer and use it in GitHub Desktop.
Debug function which dumps a table with a pretty structure.
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