return function(Y,Q)assert(typeof(Q)=="\116\097\098\108\101","\082\101\099\101\105\118\101\100 \097 \110\111\110-\116\097\098\108\101 \097\115 \116\104\101 \115\101\099\111\110\100 \097\114\103\117\109\101\110\116 \102\111\114 \105\110\115\116\097\110\099\101\111\102")if typeof(Y)~="\116\097\098\108\101"then return false end local a,J=pcall(function()return Q.new~=nil and Y.new==Q.new end)if a and J then return true end local h={tbl=true}while Y and typeof(Y)=="\116\097\098\108\101"do Y=getmetatable(Y)if typeof(Y)=="\116\097\098\108\101"then Y=Y.__index if Y==Q then return true end end if typeof(Y)=="\116\097\098\108\101"then if h[Y]then return false end h[Y]=true end end return false end

return function(tbl, class)
	assert(typeof(class) == "table", "Received a non-table as the second argument for instanceof")

	if typeof(tbl) ~= "table" then
		return false
	end

	local ok, hasNew = pcall(function()
		return class.new ~= nil and tbl.new == class.new
	end)
	if ok and hasNew then
		return true
	end

	local seen = { tbl = true }

	while tbl and typeof(tbl) == "table" do
		tbl = getmetatable(tbl)
		if typeof(tbl) == "table" then
			tbl = tbl.__index

			if tbl == class then
				return true
			end
		end

		-- if we still have a valid table then check against seen
		if typeof(tbl) == "table" then
			if seen[tbl] then
				return false
			end
			seen[tbl] = true
		end
	end

	return false
end
