local y={}function y.typeValid(y)return type(y)~="\117\115\101\114\100\097\116\097",typeof(y)end function y.scanValidity(g,H,k)if type(g)~="\116\097\098\108\101"then return y.scanValidity({input=g},{},{})end H,k=H or{},k or{"\105\110\112\117\116"}H[g]=true local o do local y,H=next(g)if type(y)=="\110\117\109\098\101\114"then o="\065\114\114\097\121"else o="\068\105\099\116\105\111\110\097\114\121"end end local T=0 for g,w in next,g do k[#k+1]=tostring(g)if type(g)=="\110\117\109\098\101\114"then if o=="\068\105\099\116\105\111\110\097\114\121"then return false,k,"\077\105\120\101\100 \065\114\114\097\121\047\068\105\099\116\105\111\110\097\114\121"elseif g%1~=0 then return false,k,"\078\111\110-\105\110\116\101\103\101\114 \105\110\100\101\120"elseif g==math.huge or g==-math.huge then return false,k,"\040-\041\073\110\102\105\110\105\116\121 \105\110\100\101\120"end elseif type(g)~="\115\116\114\105\110\103"then return false,k,"\078\111\110-\115\116\114\105\110\103 \107\101\121",typeof(g)elseif o=="\065\114\114\097\121"then return false,k,"\077\105\120\101\100 \065\114\114\097\121\047\068\105\099\116\105\111\110\097\114\121"end if o=="\065\114\114\097\121"then if T~=g-1 then return false,k,"\065\114\114\097\121 \119\105\116\104 \110\111\110-\115\101\113\117\101\110\116\105\097\108 \105\110\100\101\120\101\115"end T=g end local d,z=y.typeValid(w)if not d then return false,k,"\073\110\118\097\108\105\100 \116\121\112\101",z end if type(w)=="\116\097\098\108\101"then if H[w]then return false,k,"\067\121\099\108\105\099"end local g,o,T,d=y.scanValidity(w,H,k)if not g then return g,o,T,d end end k[#k]=nil end H[g]=nil return true end function y.getStringPath(y)return table.concat(y,"\046")end function y.warnIfInvalid(g)local H,k,o,T=y.scanValidity(g)if not H then if T then warn("\073\110\118\097\108\105\100 \097\116 "..(y.getStringPath(k)..(" \098\101\099\097\117\115\101\058 "..(o..(" \040"..(tostring(T).."\041"))))))else warn("\073\110\118\097\108\105\100 \097\116 "..(y.getStringPath(k)..(" \098\101\099\097\117\115\101\058 "..o)))end end return H end return y
-- Written by Coercii

local Verifier = {}

function Verifier.typeValid(data)
	return type(data) ~= "userdata", typeof(data)
end

function Verifier.scanValidity(tbl, passed, path)
	if type(tbl) ~= "table" then
		return Verifier.scanValidity({input = tbl}, {}, {})
	end
	passed, path = passed or {}, path or {"input"}
	passed[tbl] = true
	local tblType
	do
		local key, value = next(tbl)
		if type(key) == "number" then
			tblType = "Array"
		else
			tblType = "Dictionary"
		end
	end
	local last = 0
	for key, value in next, tbl do
		path[#path + 1] = tostring(key)
		if type(key) == "number" then
			if tblType == "Dictionary" then
				return false, path, "Mixed Array/Dictionary"
			elseif key%1 ~= 0 then  -- if not an integer
				return false, path, "Non-integer index"
			elseif key == math.huge or key == -math.huge then
				return false, path, "(-)Infinity index"
			end
		elseif type(key) ~= "string" then
			return false, path, "Non-string key", typeof(key)
		elseif tblType == "Array" then
			return false, path, "Mixed Array/Dictionary"
		end
		if tblType == "Array" then
			if last ~= key - 1 then
				return false, path, "Array with non-sequential indexes"
			end
			last = key
		end
		local isTypeValid, valueType = Verifier.typeValid(value)
		if not isTypeValid then
			return false, path, "Invalid type", valueType
		end
		if type(value) == "table" then
			if passed[value] then
				return false, path, "Cyclic"
			end
			local isValid, keyPath, reason, extra = Verifier.scanValidity(value, passed, path)
			if not isValid then
				return isValid, keyPath, reason, extra
			end
		end
		path[#path] = nil
	end
	passed[tbl] = nil
	return true
end

function Verifier.getStringPath(path)
	return table.concat(path, ".")
end

function Verifier.warnIfInvalid(input)
	local isValid, keyPath, reason, extra = Verifier.scanValidity(input)
	if not isValid then
		if extra then
			warn("Invalid at "..Verifier.getStringPath(keyPath).." because: "..reason.." ("..tostring(extra)..")")
		else
			warn("Invalid at "..Verifier.getStringPath(keyPath).." because: "..reason)
		end
	end

	return isValid
end

return Verifier
