Last active
October 26, 2019 10:41
-
-
Save TobleMiner/3e0dd3a07a7557dab94ca4f9f37babe1 to your computer and use it in GitHub Desktop.
This file contains 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
_G['vardumpstr'] = function(var, longform, prefix, refs, out) | |
prefix = prefix or '' | |
refs = refs or {} | |
out = out or '' | |
if type(var) == 'table' then | |
local cyclic = not not refs[var] | |
refs[var] = true | |
out = out .. prefix .. tostring(var) .. (cyclic and ' (cyclic)' or '') .. '\n' | |
if not cyclic then | |
prefix = prefix .. ' ' | |
for k,v in pairs(var) do | |
out = out .. prefix .. tostring(k) .. ': ' .. '(' .. type(v) .. ')\n' | |
out = vardumpstr(v, longform, prefix .. '| ', refs, out) | |
end | |
refs[var] = not longform | |
end | |
else | |
local str = tostring(var) | |
str = string.gsub(str, '[^%a%s%d%p%%%^%$%(%)%[%]%*%+%-%?_~|{}\\]', '?') | |
out = out .. prefix .. (type(var) == 'string' and '"' .. str .. '"' or str) .. '\n' | |
end | |
return out | |
end | |
_G['vardump'] = function(var, longform, prefix, refs, out) | |
print(vardumpstr(var, longform, prefix, refs, out)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment