Module:Method

local member = require('Module:Member') local utils = require('Module:Utils') local link_type = require('Module:Type').link local member_tag_descriptions = require('Module:Member tags').member_tag_descriptions

local p = {}

function p._create(args) local prefix = '' local parameter_list = '' for argn, value in ipairs(utils.trim_positional_arguments(args)) do       -- If the value contains whitespace, we assume it describes a parameter with the parameter type and name separated by whitespace. if mw.ustring.find(value, '%s') then -- If the parameter list already contains parameters, add a space and a comma before inserting another. if parameter_list ~= '' then parameter_list = parameter_list .. ", "           end

-- Get the parameter type and name from the value. local parameter_type, parameter_name, default_value = mw.ustring.match(value, '(.+)%s+(.+)%s+=%s*(.+)') if parameter_type then -- There is a default value. parameter_list = parameter_list .. link_type(parameter_type) .. " " .. mw.text.tag('var', {class="parameter-name"}, parameter_name) .. " = " .. default_value else -- There is no default value parameter_type, parameter_name = mw.ustring.match(value, '(.+)%s+(.*)') parameter_list = parameter_list .. link_type(parameter_type) .. " " .. mw.text.tag('var', {}, parameter_name) end -- Otherwise, it's a return value's type. elseif not member_tag_descriptions[value] then -- Add the return type to the prefix, adding a space before the type if there are already return types in the prefix. if prefix == '' then prefix = prefix .. link_type(value) elseif mw.title.getCurrentTitle:inNamespace('Class') then return error("Member with multiple return values") else prefix = prefix .. ", " .. link_type(value) end end end

-- Filter out return types and parameter types and names from tags. local tags = {} for tag in next, utils.array_to_set(utils.trim_positional_arguments(args)) do       if member_tag_descriptions[tag] then tags[tag] = true end end

local icon = 'Pubmethod.gif' if tags['RobloxPlaceSecurity'] then icon = 'Privmethod.gif' else for tag in pairs(tags) do           if tag:match('[Ss]ecurity') then icon = 'Protmethod.gif' end end end

return member._create { name = args.name; prefix = prefix; tags = tags; icon = icon; ["parameter list"] = parameter_list; } end

p.create = utils.make_wrapper_function(p._create)

return p