Module:Common
More actions
Documentation for this module may be created at Module:Common/doc
local p = {}
--- 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}.
---
--- @param prefix string Prefix of the argument name
--- @param args table Table of arguments
--- @return table Table of argument numbers
function p.getArgNums(prefix, args)
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
return p