function Util.RunEmbeddedCommands(U,A)A=encodeCommandEscape(A)local O={}for A in A:gmatch("\036\040\037\098\123\125\041")do local p=true local C=A:sub(2,#A-1)if C:match("\094\123\046\043\125\036")then p=false C=C:sub(2,#C-1)end O[A]=U:EvaluateAndRun(C)if p and O[A]:find("\037\115")then O[A]=string.format("\037\113",O[A])end end return decodeCommandEscape(A:gsub("\036\040\037\098\123\125\041",O))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] = dispatcher:EvaluateAndRun(commandString)

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

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