Jump to content

Module:parameters/lite/list numbers

Wiktionary වෙතින්


local function clean(x) return x and #x > 0 and x or nil end

-- implements a numbered list parameter, somewhat
return function (args, base, allow_holes, allow_empty)
	local results = {}
	local maximum_index = 0
	base = base - 1
	
	for index, value in pairs(args) do
		if type(index) == "number" and index > base then
			value = mw.text.trim(value)
			if not allow_empty then value = clean(value) end
			index = index - base
			results[index] = value
			maximum_index = math.max(maximum_index, index)
		end
	end
	
	if maximum_index > 0 then
		if not allow_holes then
			local i = 1
			local j = 1
			while i <= maximum_index do
				if results[i] then
					results[j] = results[i]
					if j < i then results[i] = nil end
					j = j + 1
				end
				i = i + 1
			end
		else
			results.maxindex = maximum_index
		end
	end
	
	return results
end
"https://si.wiktionary.org/w/index.php?title=Module:parameters/lite/list_numbers&oldid=28064" වෙතින් සම්ප්‍රවේශනය කෙරිණි