Documentation for this module may be created at Module:Calculator/doc
-- 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 '<span class="lua-calc-nodule-error">Must provide 2 values for operation</span>'
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 '<span class="lua-calc-nodule-error">Must provide 2 values for operation</span>'
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 '<span class="lua-calc-nodule-error">Must provide 2 values for operation</span>'
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 '<span class="lua-calc-nodule-error">Must provide 2 values for operation</span>'
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 '<span class="lua-calc-nodule-error">Must provide 2 values for operation</span>'
else
return tonumber( frame.args[1] ) - tonumber( frame.args[2] )
end
end
return p