Skip to content

Instantly share code, notes, and snippets.

@jthistle
Created October 21, 2017 20:17
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 jthistle/ac283f3ab7fe494297e022133a042e32 to your computer and use it in GitHub Desktop.
Save jthistle/ac283f3ab7fe494297e022133a042e32 to your computer and use it in GitHub Desktop.
function tableAsString(tbl)
toReturn = "{"
for ind, val in pairs(tbl) do
if type(val) == "table" then
toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. tableAsString(val) .. ","
else
local newVal
if type(val) == "string" then
newVal = "\"" .. val .. "\""
else
newVal = val
end
toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. newVal .. ","
end
end
toReturn = toReturn:sub(1,-2) .. "}" -- remove trailing "," and close table
return toReturn
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment