function Util.RunEmbeddedCommands(u,c)c=encodeCommandEscape(c)local I={}for c in c:gmatch("\036\040\037\098\123\125\041")do local F=true local S=c:sub(2,#c-1)if S:match("\094\123\046\043\125\036")then F=false S=S:sub(2,#S-1)end I[c]=Util.RunCommandString(u,S)if F then if I[c]:find("\037\115")or I[c]==""then I[c]=string.format("\037\113",I[c])end end end return decodeCommandEscape(c:gsub("\036\040\037\098\123\125\041",I))end

function Util.RunEmbeddedCommands(dispatcher, str)
	str = encodeCommandEscape(str)

	local results = {}
	-- We need to do this because you can't yield in the gsub function
	for text in str:gmatch("$(%b{})") do
		local doQuotes = true
		local commandString = text:sub(2, #text-1)

		if commandString:match("^{.+}$") then -- Allow double curly for literal replacement
			doQuotes = false
			commandString = commandString:sub(2, #commandString-1)
		end

		results[text] = Util.RunCommandString(dispatcher, commandString)

		if doQuotes then
			if results[text]:find("%s") or results[text] == "" then
				results[text] = string.format("%q", results[text])
			end
		end
	end

	return decodeCommandEscape(str:gsub("$(%b{})", results))
end
