Jump to content

Module:Template invocation: Difference between revisions

validate the keys and values in the args table in p.invocation
(add a p.name function to find the template name, use checkType with p.invocation, and add some function description comments)
(validate the keys and values in the args table in p.invocation)
Line 60: Line 60:
checkType('invocation', 3, format, 'string', true)
checkType('invocation', 3, format, 'string', true)


-- Copy the invocation args and convert magic words.
-- Validate the args table and make a copy to work from. We need to
-- We need to make a copy of the table rather than just using the original,
-- make a copy of the table rather than just using the original, as
-- as some of the values may be erased when building the invocation.
-- some of the values may be erased when building the invocation.
local invArgs = {}
local invArgs = {}
for k, v in pairs(args) do
for k, v in pairs(args) do
local typek = type(k)
local typev = type(v)
if type(k) ~= 'string' and type(k) ~= 'number'
or type(v) ~= 'string' and type(v) ~= 'number'
then
error("invalid arguments table in parameter #2 of " ..
"'invocation' (keys and values must be strings or numbers)", 2)
end
invArgs[k] = v
invArgs[k] = v
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.