Module:Ingredient link list

local p = {} local f = mw.getCurrentFrame

function p.genlink(args) if args[1] == nil then return { errno = 1 } end local sep = args.sep or ';' local firstarg = args.firstarg or 1 if tonumber(firstarg) >= 2 and (not args.maxargs) then return { errno = 2 } end local maxargs = args.maxargs or (#args - 1) local output_array = {} for i = firstarg, maxargs do		local name_pieces = {} for current_name in mw.text.gsplit(mw.text.trim(args[i]), sep) do			local trimmed_name = mw.text.trim(current_name) if trimmed_name ~= '' then name_pieces[trimmed_name] = true end end local converted_names = {} for name, exist in pairs(name_pieces) do			if exist then local prefix if string.find(name, '^Matching ') then prefix = 'Matching ' name = string.gsub(name, '^Matching ', '') elseif string.find(name, '^Any ') then prefix = 'Any ' name = string.gsub(name, '^Any ', '') else prefix = '' end table.insert(converted_names, f:preprocess(prefix ..  .. name .. )) end end table.insert(output_array, table.concat(converted_names, ' or ')) end return table.concat(output_array, ' + ') end

function p.main local args = require('Module:ProcessArgs').merge(true) local result = p.genlink(args) if type(result) == 'string' then return result end local error_prompts = { 'The first anonymous parameter could not be empty!', 'When the argument "firstarg" is equals to or greater than 2, the argument "maxargs" must be set!' }	return f:expandTemplate{ title = 'Error', args = { error_prompts[result.errno] } } end

return p