m (Ihaveahax moved page Module:FBI QR codes to Module:FBI QR code without leaving a redirect: match template name) |
No edit summary |
||
(26 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local args = {} | |||
local p = {} | local p = {} | ||
Line 23: | Line 25: | ||
-- for the specified prefix. For example, if the prefix was 'data', and | -- for the specified prefix. For example, if the prefix was 'data', and | ||
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. | -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. | ||
local function getArgNums(prefix | local function getArgNums(prefix) | ||
local nums = {} | local nums = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
Line 33: | Line 35: | ||
end | end | ||
function p.makeSections( | function p.makeSections() | ||
local sections = {} | local sections = {} | ||
local nums = union(getArgNums('name' | local nums = union(getArgNums('name'), getArgNums('url')) | ||
for k, v in ipairs(nums) do | for k, v in ipairs(nums) do | ||
local name = args['name' .. tostring( | local name = args['name' .. tostring(num)] | ||
local url = args[' | local url = args['name' .. tostring(num)] | ||
if name and url then | if name and url then | ||
table.insert(sections) | |||
table.insert(sections | |||
end | end | ||
end | end | ||
end | end | ||
function p. | function p.main(frame) | ||
-- adapted from [[Module:Infobox]] | |||
if frame == mw.getCurrentFrame() then | |||
args = frame:getParent().args | |||
else | |||
args = frame | |||
end | end | ||
local sections = p.makeSections( | local sections = p.makeSections() | ||
end | end | ||
function p. | function p.test(frame) | ||
return frame:getParent():callParserFunction('#qrlite', frame:getParent().args['1']) | |||
end | end | ||
return p | return p |
Revision as of 04:46, 4 July 2022
Documentation for this module may be created at Module:FBI QR code/doc
local args = {}
local p = {}
-- from [[Module:Infobox]]
-- Returns the union of the values of two tables, as a sequence.
local function union(t1, t2)
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
for k, v in pairs(t2) do
vals[v] = true
end
local ret = {}
for k, v in pairs(vals) do
table.insert(ret, k)
end
return ret
end
-- from [[Module:Infobox]]
-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local function getArgNums(prefix)
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
table.sort(nums)
return nums
end
function p.makeSections()
local sections = {}
local nums = union(getArgNums('name'), getArgNums('url'))
for k, v in ipairs(nums) do
local name = args['name' .. tostring(num)]
local url = args['name' .. tostring(num)]
if name and url then
table.insert(sections)
end
end
end
function p.main(frame)
-- adapted from [[Module:Infobox]]
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame
end
local sections = p.makeSections()
end
function p.test(frame)
return frame:getParent():callParserFunction('#qrlite', frame:getParent().args['1'])
end
return p