
function table.tostring(tt)
	return string.format("{\n%s\n}",_tabletostring(tt))
end

function _tabletostring(tt, indent, done)
	done = done or {}
	indent = indent or 1
	if type(tt) == "table" then
		local sb = {}
		for key, value in pairs (tt) do
			table.insert(sb, string.rep ("\t", indent)) -- indent it
			local keystring=key
			if type(key)=="number" then keystring=string.format("[%d]",key) end
			if type(key)=="string" then keystring=string.format("[\"%s\"]",key) end
			if type (value) == "table" and not done [value] then
				done [value] = true
				table.insert(sb, string.format("%s={\n",keystring));
				table.insert(sb, _tabletostring (value, indent + 1, done))
				table.insert(sb, string.rep ("\t", indent)) -- indent it
				table.insert(sb, "},\n");
			else
				table.insert(sb, string.format("%s = %s,\n",keystring, tostring(value)))
			end
		end
		return table.concat(sb)
	else
		return tt .. "\n"
	end
end