Skip to content

Instantly share code, notes, and snippets.

@Torte446
Created December 21, 2020 16:35
Show Gist options
  • Save Torte446/cad94cf33bf06a70ba96ad3c9f1938ac to your computer and use it in GitHub Desktop.
Save Torte446/cad94cf33bf06a70ba96ad3c9f1938ac to your computer and use it in GitHub Desktop.
function tab2str(tab)
local s = "{"
for i,v in pairs(tab) do
if type(v) == "table" then
s = s.."{"
for it,vt in pairs(v) do
if type(vt) == "table" then
s = s.."{"
s = s..stringall.table(vt)
if it ~= #v then
s = s..","
end
elseif it ~= #v then
if type(vt) == "string" then
s = s..'"'..vt..'"'..","
else
s = s..tostring(vt)..","
end
else
s = s..tostring(vt).."}"
end
end
elseif i ~= #tab then
if type(v) == "string" then
s = s..'"'..v..'"'..","
else
s = s..tostring(v)..","
end
elseif type(v) == "string" then
s = s..'"'..v..'"'.."}"
else
s = s..tostring(v).."}"
end
end
return s;
end
@Torte446
Copy link
Author

Torte446 commented Dec 21, 2020

tab2str({1,2,{4,5,{6,7},"ab","cd"}}) will return {1,2,{4,5,{6,7},"ab","cd"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment