Module:Mmgtable2
Documentation for this module may be created at Module:Mmgtable2/doc
local p = {}
local MAX_INPUTS = 10
local MAX_OUTPUTS = 10
local function calculateTotal(args, prefix, max)
local total = 0
for i = 1, max do
local num = tonumber(args[prefix .. i .. 'num']) or 0
local value = tonumber(args[prefix .. i .. 'value']) or 0
total = total + (num * value)
end
return total
end
function p.profit(frame)
local args = frame:getParent().args
local frameArgs = frame.args
-- Merge frame.args into args in case of direct #invoke
for k, v in pairs(frameArgs) do
if v ~= '' then
args[k] = v
end
end
local inputs = calculateTotal(args, 'Input', MAX_INPUTS)
local outputs = calculateTotal(args, 'Output', MAX_OUTPUTS)
local profit = outputs - inputs
return tostring(profit)
end
return p