Modul:Benutzer:Kpfiwa/calc/func

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:Benutzer:Kpfiwa/calc/func/Doku erstellt werden

--- Grundidee von :en:Module:Sandbox/Lemondoge/Calc 
---- Ausschließlich Berechnungen bei Bedarf
local p = {}

function templatevalues(t) -- processes all contained templates into values
	--[[
	
	frame:expandTemplate{ title = title, args = table } ?????
	https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual/de#frame:expandTemplate
	
	z, zr= string.gsub(t,reg,prep("%1") or nil);zz=zz+1
  if zr > 0 then
		return z, zr
	end
while zzr do -- derzeit MIST
   txt,zzr=filter(txt)
     if zzr then print(txt,zzr) end
end --]]
return t
end



-- https://stackoverflow.com/questions/20598937/handling-cr-line-endings-in-lua >> 
local function cr_lines(s)
    --return s:gsub('\r\n?', '\n'):gmatch('(.-)\n')
    return s:gsub('\n', '\n\nX')
end

function nowiex(txt,frame) --- unstrip nowiki & process all including templates
    	return frame:preprocess(mw.text.unstripNoWiki(txt))
end

local function RError(msg)
	return mw.ustring.format('<b class="error">%s</b>', msg)
end

function p.add(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 + num2
end

function p.addition(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 + num2
end


function p.minus(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 - num2
end

function p.subtraction(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 - num2
end

function p.times(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	local errordetect = tonumber(frame.args[3])
	if num2 == 0 and errordetect ~= 1 then
		return RError("You cannot multiply a number by zero.")
	else
		return num1 * num2
	end
end

function p.multiplication(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 * num2
end

function p.double(frame)
	local num1 = tonumber(frame.args[1])
	return num1 * 2
end

function p.div(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	local antinotanumber = tonumber(frame.args[3])
	if num1 == 0 and num2 == 0 and antinotanumber == 1 then
		return 1
	else
		return num1 / num2
	end
end

function p.division(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	local antinotanumber = tonumber(frame.args[3])
	if num1 == 0 and num2 == 0 and antinotanumber == 1 then
		return 1
	else
		return num1 / num2
	end
end

function p.mod(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 % num2
end

function p.modulo(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 % num2
end

function p.exp(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 ^ num2
end

function p.exponentiation(frame)
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 ^ num2
end

return p