Module:Pn: Difference between revisions

Content deleted Content added
debug
m Protected "Module:Pn": High-risk template or module: 259 transclusions (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))
 
(6 intermediate revisions by one other user not shown)
Line 2:
Module that returns one value from a list of unnamed parameters
Named parameter idx is the index of the parameter that is to be returned
NegativesNegative indices count backward from the end of the list
==]]
 
Line 8:
 
p.getVal = function(frame)
local args = frame.args{}
-- copy arguments from frame object and its parent
for k, v in pairs(frame.args) do
args[k] = v
end
args for =k, v in pairs(frame:getParent().args) do
args[k] = v
end
if not args[1] then
return nil
args = frame:getParent().args
if not args[1] then return error("No values supplied") end
end
local idx = tonumber(args.idx) or 1
if idx < 10 then idx = #args + idx + 1 end
ifreturn idx > #args then [idx = #args end]
return args[idx] .. #args .. idx
end