function Util.RunEmbeddedCommands(x,t)t=encodeCommandEscape(t)local Z={}for t in t:gmatch("\036\040\037\098\123\125\041")do local o=true local b=t:sub(2,#t-1)if b:match("\094\123\046\043\125\036")then o=false b=b:sub(2,#b-1)end Z[t]=Util.RunCommandString(x,b)if o then if Z[t]:find("\037\115")or Z[t]==""then Z[t]=string.format("\037\113",Z[t])end end end return decodeCommandEscape(t:gsub("\036\040\037\098\123\125\041",Z))end
--- Runs embedded commands and replaces them
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
