🇮🇷 Iran Proxy | https://www.wikipedia.org/wiki/Module:User:Rich_Farmbrough/Indexer.lua
Jump to content

Module:User:Rich Farmbrough/Indexer.lua

From Wikipedia, the free encyclopedia
local getArgs = require('Module:Arguments').getArgs
local p = {}

local function make_list(base, start, count)
	start = tonumber(start)
	finish = start + tonumber(count) - 1
	if not (start and finish) or finish < start then
		return ''
	end
	local out = {}
	table.insert(out, string.format("===%d-%d===\n", start, finish))
	for i = start, finish do
		table.insert(out, string.format("* [[%s %d]]\n", base, i))
	end
    next_start = finish + 1
    table.insert(out, string.format("<!-- {{Subst:User:Rich Farmbrough/Indexer|%d|count=%d}} -->\n", next_start, count))
	return table.concat(out)
end

function p.main(frame)
    local args = getArgs(frame)
	local base  = (args.base or '')
	local start = tonumber(args.start) 
    if not start then
       error('start is required (unnumbered param 1)') -- Message only applicable if called from specific template.
    end
    local count = tonumber(args.count)
    if not count then
       error('start is required (count = or unnumbered param 2)') -- Message only applicable if called from specific template.
    end
    -- return string.format("%s %d %d", base, start, count)
	return make_list(base, start, count)
end

return p