Notwendiges Modul für die Benutzung der Vorlage {{Marker}}


-- Parameters check and conversion

local pc = {}

local errorMsg = {
	['unknownParam']  = ' Unbekannter Parameter: ',
	['unknownParams'] = ' Unbekannte Parameter: ',
	['maintenance']   = '[[Category:Marker: Unbekannte Parameter]]'
}

function pc.checkNumber( s )
	if s == '' then return s end

	local n = tonumber( s )
	if n == nil then return '' else return n end
end

function pc.round( n, idp )
	local m = 10^( idp or 0 )
	if n >= 0 then return math.floor( n * m + 0.5 ) / m
		else return math.ceil( n * m - 0.5 ) / m
	end
end

function pc.checkParams( args, arr, cat )
    local i = 0
	local s = ''
	local c = cat 
	if (c == nil) or (c == '') then c = errorMsg.maintenance end
	for k, v in pairs( args ) do
		if arr[k] == nil then
			if s == '' then s = "''" .. k .. "''" 
			else s = s .. ", ''" .. k .. "''" end
			i = i + 1
		end
	end

	if i == 1 then s = errorMsg.unknownParam .. s
	elseif i > 1 then s = errorMsg.unknownParams .. s end
	if s ~= '' then
		s = '<span class="error">' .. s .. '</span>' .. c
	end

	return s
end

function pc.setDefaults( args, arr )
	for k, v in pairs( args ) do
		if (v == nil) and (arr[k] ~= nil) then v = arr[k] end
	end
	return args
end

return pc