Module:Mmgtable2
Documentation for this module may be created at Module:Mmgtable2/doc
local p = {}
-- Maximum allowed entries
local MAX_INPUTS = 75
local MAX_OUTPUTS = 75
-- Main function to return only the profit as a number
function p.profit(frame)
local args = frame:getParent().args
local inputs = calculateTotal(args, 'Input', MAX_INPUTS)
local outputs = calculateTotal(args, 'Output', MAX_OUTPUTS)
local profit = outputs - inputs
return tostring(profit)
end
-- Calculates total value from prefixed args (Input/Output)
function calculateTotal(args, prefix, max)
local total = 0
for i = 1, max do
local name = args[prefix .. i]
if not name or name == '' then break end
local qty = tonumber(args[prefix .. i .. 'num']) or 1
local value = tonumber(args[prefix .. i .. 'value']) or 0
total = total + (qty * value)
end
return total
end
return p