Module:ListMembersBySecurity

local member_link = require('Module:MemberLink')

local p = {}

--% This function gets members by their security. --% Properties have separate read and write security, so they can have two different securities. In that case, they are present in both tables. --: (table) the members by security: keys are the security, values are the array of members with that security local function get_members_by_security local members_by_security = {} for _, class in ipairs(require("Module:APIClasses")) do       for _, member in ipairs(class.Members) do            if member.Security then if type(member.Security) == "string" then if member.Security ~= "None" then if not members_by_security[member.Security] then members_by_security[member.Security] = {} end table.insert(members_by_security[member.Security], {class.Name, member}) end elseif type(member.Security) == "table" then local read_security = member.Security.Read local write_security = member.Security.Write if read_security ~= "None" or write_security ~= "None" then if read_security == write_security then if not members_by_security[read_security] then members_by_security[read_security] = {} end table.insert(members_by_security[read_security], {class.Name, member}) else if read_security ~= "None" then if not members_by_security[read_security] then members_by_security[read_security] = {} end table.insert(members_by_security[read_security], {class.Name, member}) end if write_security ~= "None" then if not members_by_security[write_security] then members_by_security[write_security] = {} end table.insert(members_by_security[write_security], {class.Name, member}) end end end else return error("unexpected member security type: " .. type(member.Security)) end end end end return members_by_security end

--% This function generates a list of members by their security. --: (string) the list of members function p.list_members_by_security local members_by_security = get_members_by_security local sorted_securities = {} for security in pairs(members_by_security) do       table.insert(sorted_securities, security) end table.sort(sorted_securities) local output = "" for _, security in ipairs(sorted_securities) do       output = output .. "== " .. security .. " ==\n" for _, class_member in ipairs(members_by_security[security]) do           local class_name, member = class_member[1], class_member[2] output = output .. "* " .. member_link.make_member_link_with_icon(class_name, member) if type(member.Security) == "string" then assert(member.Security == security, "member " .. member.Name .. " of class " .. class_name .. " has unexpected security " .. member.Security .. " instead of " .. security) output = output .. "\n" elseif type(member.Security) == "table" then local read_security = member.Security.Read local write_security = member.Security.Write if read_security == security then if write_security == security then output = output .. " (read, write)\n" else output = output .. " (read)\n" end elseif write_security == security then output = output .. " (write)\n" else return error("member " .. member.Name .. " of class " .. class_name .. " does not have expected security " .. security) end else return error("unexpected member security type: " .. type(member.Security)) end end end return output end

return p