Difference between revisions of "Module:Used by/Sandbox"

From Team Fortress Wiki
Jump to: navigation, search
Line 9: Line 9:
 
     local count = -1
 
     local count = -1
 
     local args = frame.args
 
     local args = frame.args
     for arg in pairs(args) do
+
     for _, arg in ipairs(args) do
 
         first = first or arg
 
         first = first or arg
 
         count = count + 1  
 
         count = count + 1  
Line 15: Line 15:
 
     if first == nil then
 
     if first == nil then
 
         args = frame:getParent().args
 
         args = frame:getParent().args
         for arg in pairs(args) do
+
         for _, arg in ipairs(args) do
 
             first = first or arg
 
             first = first or arg
 
             count = count + 1
 
             count = count + 1
Line 21: Line 21:
 
     end
 
     end
 
    
 
    
     assert(false, 'First:' .. first)
+
     assert(false, 'First:' .. first .. ' Count:' .. count)
    count = count - 1
 
 
     if first == 'all' then
 
     if first == 'all' then
 
         return common_string{'infobox-used-by-all'}
 
         return common_string{'infobox-used-by-all'}

Revision as of 06:23, 18 March 2023

Documentation for this module may be created at Module:Used by/Sandbox/doc

local p = {}

function common_string(args)
  return mw.getCurrentFrame():expandTemplate{title='Common string', args=args}
end

function p.classes(frame)
    local first = nil
    local count = -1
    local args = frame.args
    for _, arg in ipairs(args) do
        first = first or arg
        count = count + 1 
    end
    if first == nil then
        args = frame:getParent().args
        for _, arg in ipairs(args) do
            first = first or arg
            count = count + 1
        end
    end
  
    assert(false, 'First:' .. first .. ' Count:' .. count)
    if first == 'all' then
        return common_string{'infobox-used-by-all'}
    elseif first == 'all-except' then
        return common_string{'infobox-used-by-all-except-' .. count, unpack(args)}
    else
        return common_string{'infobox-used-by-' .. count, unpack(args)}
    end
end

return p