function serializeRec (o, prefix)
	if type(o) == "number" then
		io.write(o)
	elseif type(o) == "boolean" then
		io.write(tostring(o))
	elseif type(o) == "string" then
		io.write(string.format("%q", o))
	elseif type(o) == "table" then
		io.write("{\n")
		local prefix2 = prefix .. "\t"
		io.write(prefix2)

		local indices = {}

		for k,v in ipairs(o) do
			indices[k] = 0
			serializeRec(v, prefix2)		
			io.write(", ")
		end

		local keys = {}
		for k in pairs(o) do
			if indices[k] == nil then	    				
				table.insert(keys, k)
			end
		end
		table.sort(keys)

		for i,k in ipairs(keys) do
			v = o[k]
			if type(k) == "string" and not string.find(k, " ") then
				io.write(k, " = ")
			else
				io.write("[")
				serializeRec(k, prefix2)
				io.write("] = ")
			end
			serializeRec(v, prefix2)
			io.write(",\n", prefix2)				
		end			

		io.write("\n", prefix, "}")
	else
		error("cannot serialize a " .. type(o))
	end
end

function serialize(o)
	io.write("function data()", "\n")
	io.write("return ")
	serializeRec(o, "")
	io.write("\n", "end")
end
