Module:Calculator

-- Calculator - Easily add arithmetic operations to wiki pages -- Written by Shining-Armor -- Version 0.1

local p = {}

function p.empty( s ) if s == nil or s == '' then return true else return false end end

function p.addition( frame ) if p.empty( frame.args[1] ) or p.empty( frame.args[2] ) then return ' Must provide 2 values for operation ' else return tonumber( frame.args[1] ) + tonumber( frame.args[2] ) end end

function p.division( frame ) if p.empty( frame.args[1] ) or p.empty( frame.args[2] ) then return ' Must provide 2 values for operation ' else return tonumber( frame.args[1] ) / tonumber( frame.args[2] ) end end

function p.modulo( frame ) if p.empty( frame.args[1] ) or p.empty( frame.args[2] ) then return ' Must provide 2 values for operation ' else return tonumber( frame.args[1] ) % tonumber( frame.args[2] ) end end

function p.multiplication( frame ) if p.empty( frame.args[1] ) or p.empty( frame.args[2] ) then return ' Must provide 2 values for operation ' else return tonumber( frame.args[1] ) * tonumber( frame.args[2] ) end end

function p.subtraction( frame ) if p.empty( frame.args[1] ) or p.empty( frame.args[2] ) then return ' Must provide 2 values for operation ' else return tonumber( frame.args[1] ) - tonumber( frame.args[2] ) end end

return p