local function quote(str, lvl)
	--lvl = lvl or 
	local rp = "]"..(lvl or "").."]"
	if string.match(str, rp) then
		return quote(str, (lvl or "") .. "=")
	end

	return "["..(lvl or "").."["..str..rp
end

function serialize_lua_value(val)
	if type(val) == "number" then
		return tostring(val)
	elseif type(val) == "string" then
		-- TODO: use different quotes if ']]' appears in the value
		return quote(val)
	elseif type(val) == "table" then
		local r = "{"
		for k, v in pairs(val) do
			r = r .. "[ "..serialize_lua_value(k).." ]="..serialize_lua_value(v)..","
		end
		return r .. "}"
	elseif val == nil then
		return "nil"
	elseif val == false then
		return "false"
	elseif val == true then
		return "true"
	end
	error("serialization failed")
end
