Module:MergeArgs

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:12, 17 October 2024 (Created page with "-- <pre> local p = {} function p.merge(frame) local origArgs = frame.args local parentArgs = frame:getParent().args local args = {} for k, v in pairs(origArgs) do v = mw.text.trim(tostring(v)) if v ~= '' then args[k] = v end end for k, v in pairs(parentArgs) do v = mw.text.trim(tostring(v)) if v ~= '' then args[k] = v end end return args end -- </pre>"). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Module documentation
This documentation is transcluded from Module:MergeArgs/doc. [edit] [history] [purge]

This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
mergeFrameMerges the parent and frame args returning a table containing the arg values instead of an empty table with an attached metatable. Parent args overwrite invoke args allowing invoke args to be used as a "default" value for an argument.

-- <pre>
local p = {}

function p.merge(frame)
	local origArgs = frame.args
	local parentArgs = frame:getParent().args
	local args = {}
	
	for k, v in pairs(origArgs) do
		v = mw.text.trim(tostring(v))
		if v ~= '' then
			args[k] = v
		end
	end
 
	for k, v in pairs(parentArgs) do
		v = mw.text.trim(tostring(v))
		if v ~= '' then
			args[k] = v
		end
	end
 
	return args
end
-- </pre>