function Util.EmulateTabstops(M,l)local v=0 local Z=#M local w=table.create(Z)for Z=1,Z,1 do local Y=string.sub(M,Z,Z)if Y=="\t"then local M=l-v%l table.insert(w,string.rep(" ",M))v+=M else table.insert(w,Y)if Y=="\n"then v=0 elseif Y~="\r"then v+=1 end end end return table.concat(w)end function Util.Mutex()local M={}local l=false return function()if l then table.insert(M,coroutine.running())coroutine.yield()else l=true end return function()if#M>0 then coroutine.resume(table.remove(M,1))else l=false end end end end return Util

function Util.EmulateTabstops(text, tabWidth)
	local column = 0
	local textLength = #text
	local result = table.create(textLength)
	for i = 1, textLength do
		local char = string.sub(text, i, i)
		if char == "\t" then
			local spaces = tabWidth - column % tabWidth
			table.insert(result, string.rep(" ", spaces))
			column += spaces
		else
			table.insert(result, char)
			if char == "\n" then
				column = 0 -- Reset column counter on newlines
			elseif char ~= "\r" then
				column += 1
			end
		end
	end
	return table.concat(result)
end

function Util.Mutex()
	local queue = {}
	local locked = false

	return function ()
		if locked then
			table.insert(queue, coroutine.running())
			coroutine.yield()
		else
			locked = true
		end

		return function()
			if #queue > 0 then
				coroutine.resume(table.remove(queue, 1))
			else
				locked = false
			end
		end
	end
end

return Util
