local X={}function X.typeValid(X)return type(X)~="\117\115\101\114\100\097\116\097",typeof(X)end function X.scanValidity(G,F,c)if type(G)~="\116\097\098\108\101"then return X.scanValidity({input=G},{},{})end F,c=F or{},c or{"\105\110\112\117\116"}F[G]=true local T do local X=next(G)if type(X)=="\110\117\109\098\101\114"then T="\065\114\114\097\121"else T="\068\105\099\116\105\111\110\097\114\121"end end local a=0 for G,I in next,G do c[#c+1]=tostring(G)if type(G)=="\110\117\109\098\101\114"then if T=="\068\105\099\116\105\111\110\097\114\121"then return false,c,"\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,c,"\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,c,"\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,c,"\078\111\110-\115\116\114\105\110\103 \107\101\121",typeof(G)elseif T=="\065\114\114\097\121"then return false,c,"\077\105\120\101\100 \065\114\114\097\121\047\068\105\099\116\105\111\110\097\114\121"end if T=="\065\114\114\097\121"then if a~=G-1 then return false,c,"\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 a=G end local K,n=X.typeValid(I)if not K then return false,c,"\073\110\118\097\108\105\100 \116\121\112\101",n end if type(I)=="\116\097\098\108\101"then if F[I]then return false,c,"\067\121\099\108\105\099"end local G,T,a,K=X.scanValidity(I,F,c)if not G then return G,T,a,K end end c[#c]=nil end F[G]=nil return true end function X.getStringPath(X)return table.concat(X,"\046")end function X.testValidity(G)local F,c,T,a=X.scanValidity(G)if not F then if a then return"\073\110\118\097\108\105\100 \097\116 "..(X.getStringPath(c)..(" \098\101\099\097\117\115\101\058 "..(T..(" \040"..(tostring(a).."\041")))))else return"\073\110\118\097\108\105\100 \097\116 "..(X.getStringPath(c)..(" \098\101\099\097\117\115\101\058 "..T))end end end return X
-- 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 = 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.testValidity(input)
	local isValid, keyPath, reason, extra = Verifier.scanValidity(input)
	if not isValid then
		if extra then
			return "Invalid at "
				.. Verifier.getStringPath(keyPath)
				.. " because: "
				.. reason
				.. " ("
				.. tostring(extra)
				.. ")"
		else
			return "Invalid at " .. Verifier.getStringPath(keyPath) .. " because: " .. reason
		end
	end
end

return Verifier
