function Registry.RegisterType(u,o,T)if not o or typeof(o)~="\115\116\114\105\110\103"then error("\073\110\118\097\108\105\100 \116\121\112\101 \110\097\109\101 \112\114\111\118\105\100\101\100\058 \110\105\108")end if not o:find("\094\091\037\100\037\108\093\037\119\042\036")then error(("\073\110\118\097\108\105\100 \116\121\112\101 \110\097\109\101 \112\114\111\118\105\100\101\100\058 \"\037\115\"\044 \116\121\112\101 \110\097\109\101\115 \109\117\115\116 \098\101 \097\108\112\104\097\110\117\109\101\114\105\099 \097\110\100 \115\116\097\114\116 \119\105\116\104 \097 \108\111\119\101\114-\099\097\115\101 \108\101\116\116\101\114 \111\114 \097 \100\105\103\105\116\046"):format(o))end for T in pairs(T)do if u.TypeMethods[T]==nil then error("\085\110\107\110\111\119\110 \107\101\121\047\109\101\116\104\111\100 \105\110 \116\121\112\101 \""..(o..("\"\058 "..T)))end end if u.Types[o]~=nil then error(("\084\121\112\101 \"\037\115\" \104\097\115 \097\108\114\101\097\100\121 \098\101\101\110 \114\101\103\105\115\116\101\114\101\100\046"):format(o))end T.Name=o T.DisplayName=T.DisplayName or o u.Types[o]=T if T.Prefixes then u:RegisterTypePrefix(o,T.Prefixes)end end function Registry.RegisterTypePrefix(u,o,T)if not u.TypeAliases[o]then u.TypeAliases[o]=o end u.TypeAliases[o]=("\037\115 \037\115"):format(u.TypeAliases[o],T)end function Registry.RegisterTypeAlias(u,o,T)assert(u.TypeAliases[o]==nil,("\084\121\112\101 \097\108\105\097\115 \037\115 \097\108\114\101\097\100\121 \101\120\105\115\116\115\033"):format(T))u.TypeAliases[o]=T end
--- Registers a type in the system.
-- name: The type Name. This must be unique.
function Registry:RegisterType(name, typeObject)
	if not name or typeof(name) ~= "string" then
		error("Invalid type name provided: nil")
	end

	if not name:find("^[%d%l]%w*$") then
		error(
			('Invalid type name provided: "%s", type names must be alphanumeric and start with a lower-case letter or a digit.'):format(
				name
			)
		)
	end

	for key in pairs(typeObject) do
		if self.TypeMethods[key] == nil then
			error('Unknown key/method in type "' .. name .. '": ' .. key)
		end
	end

	if self.Types[name] ~= nil then
		error(('Type "%s" has already been registered.'):format(name))
	end

	typeObject.Name = name
	typeObject.DisplayName = typeObject.DisplayName or name

	self.Types[name] = typeObject

	if typeObject.Prefixes then
		self:RegisterTypePrefix(name, typeObject.Prefixes)
	end
end

function Registry:RegisterTypePrefix(name, union)
	if not self.TypeAliases[name] then
		self.TypeAliases[name] = name
	end

	self.TypeAliases[name] = ("%s %s"):format(self.TypeAliases[name], union)
end

function Registry:RegisterTypeAlias(name, alias)
	assert(self.TypeAliases[name] == nil, ("Type alias %s already exists!"):format(alias))
	self.TypeAliases[name] = alias
end
