Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

Module:PrintMultiple

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here.

A very general module to avoid multiple consecutive invokes of the same module. Most of the available arguments should usually be defined in templates to allow the user to write out as little as possible.

Required Args

  • |module=
  • |function=

Optional Args

  • |sep=, if undefined there will be no separator/delimiter between calls of the module

Argument Args

  • |arg_@@@@ expects a comma-separated list of arguments for each instance of the variable @@@@ (if comma-separated is a problem tell River to allow the separator to be user-defined as well but for now it's just comma)
  • |all_@@@@ provides a constant to be used as the value for @@@@ in each call to the module (for example you might want to do |all_data=ItemSprite

Example


local util_args = require('Module:ArgsUtil')
local util_text = require('Module:TextUtil')
local p = {}

function p.printMultiple( frame )
	local args = util_args.overwrite(frame)
	
	local m = require('Module:' .. args['module'])[args['function']]
	
	local modargs = {}
	local constants = {}
	
	for key, value in pairs(args) do
		-- non constant args will start with arg_
		if string.sub(key,0,4) == 'arg_' then
			-- get all of the individual arg values
			tbl = util_text.split(value,"%s*,%s*")
			local key2 = tonumber(string.sub(key, 5)) or string.sub(key, 5)
			-- assign each arg value to the right instance of the module arguments
			for i, j in ipairs(tbl) do
				if not modargs[i] then modargs[i] = {} end
				if j ~= '' then
					modargs[i][key2] = j
				end
			end
		-- constant args will start with all_ so we just have to track those one time each and then we'll append them to modargs later
		elseif string.sub(key,0,4) == 'all_' then
			local key2 = tonumber(string.sub(key, 5)) or string.sub(key, 5)
			constants[key2] = value
		end
	end
	
	local text = {}
	
	for i, arg_tbl in ipairs(modargs) do
		for ckey, cvalue in pairs(constants) do
			arg_tbl[ckey] = tonumber(cvalue) or cvalue
		end
		text[i] = table.concat{m(arg_tbl)}
	end
	
	local output = table.concat(text,args['sep'] or "")
	
	return output
end

return p