Skip to content

Instantly share code, notes, and snippets.

@justnom
justnom / table_to_string.lua
Created March 27, 2014 19:34
Lua table to string
-- Convert a lua table into a lua syntactically correct string
function table_to_string(tbl)
local result = "{"
for k, v in pairs(tbl) do
-- Check the key type (ignore any numerical keys - assume its an array)
if type(k) == "string" then
result = result.."[\""..k.."\"]".."="
end
-- Check the value type