Module:TypeList

local utils = require("Module:Utils")

local p = {}

--% This function generates a list of types by category. --: (string) the list of types, with a section for each category function p.list_types_by_category local categories = {} for _, class in pairs(require("Module:APIClasses")) do       for _, member in pairs(class.Members) do            if member.ValueType then if not categories[member.ValueType.Category] then categories[member.ValueType.Category] = {} end categories[member.ValueType.Category][member.ValueType.Name] = true end if member.ReturnType then if not categories[member.ReturnType.Category] then categories[member.ReturnType.Category] = {} end categories[member.ReturnType.Category][member.ReturnType.Name] = true end if member.Parameters then for _, parameter in pairs(member.Parameters) do                   if parameter.Type then if not categories[parameter.Type.Category] then categories[parameter.Type.Category] = {} end categories[parameter.Type.Category][parameter.Type.Name] = true end end end end end local sorted_categories = {} for category in pairs(categories) do       table.insert(sorted_categories, category) end table.sort(sorted_categories) local output = "" for _, category in ipairs(sorted_categories) do       output = output .. "== " .. category .. " ==\n" local types = utils.set_to_array(categories[category]) table.sort(types) for _, api_type in ipairs(types) do           if category == "Class" then output = output .. "* \n" else output = output .. "* " .. api_type .. "\n" end end end return output end

--% This function generates a list of types used in the API with a certain category. --@ category (string) the category name --: (string) the list of types function p.make_list_of_types_with_category(category) local types = {} for _, class in pairs(require("Module:APIClasses")) do       for _, member in pairs(class.Members) do            if member.ValueType and member.ValueType.Category == category then types[member.ValueType.Name] = true end if member.ReturnType and member.ReturnType.Category == category then types[member.ReturnType.Name] = true end if member.Parameters then for _, parameter in pairs(member.Parameters) do                   if parameter.Type and parameter.Type.Category == category then types[parameter.Type.Name] = true end end end end end types = utils.set_to_array(types) table.sort(types) local output = "" for _, api_type in pairs(types) do       output = output .. "* " .. api_type .. "\n" end return output end

function p._list_types_with_category(args) return p.make_list_of_types_with_category(args.category) end p.list_types_with_category = utils.make_wrapper_function(p._list_types_with_category)

return p