Module:CVTotal

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:CVTotal/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:CVTotal/doc. [edit]
Module:CVTotal's function simple is invoked by Template:CVTotal.
Module:CVTotal requires Module:Arguments.
Module:CVTotal requires Module:Array.
Module:CVTotal requires Module:Calcvalue.
Module:CVTotal requires strict.
Module:CVTotal is required by Module:Calcvalue.
Module:CVTotal is required by Module:Calcvalue/sandbox.
Module:CVTotal is required by Module:Ritual component cost.
Function list
L 32 — p.simple
L 46 — simple

Lua module implementing {{CVTotal}} for simpler usage of {{calcvalue}} sums.


--------------------------------------------------------------------------------
-- Lua module implementing {{CVTotal}} for simpler usage of {{calcvalue}} sums.
--
-- @module cvTotal
-- @alias  p
-- @author [[User:ExE Boss]]
-- @require [[Module:Arguments]]
-- @require [[Module:Calcvalue]]
-- @require [[Module:GETotal]]
-- @require [[Module:Array]]
--------------------------------------------------------------------------------

require("strict");

local getArgs = require("Module:Arguments").getArgs;
local cvPrice = require("Module:Calcvalue")._get;
local sum = require("Module:Array").sum;

local p = {};
local simple, sumPrices;

--------------------------------------------------------------------------------
-- For simple sets, 1 item at a time
-- {{CVTotal|a|b|c}} will add the {{calcvalue}} prices of a, b, and c
--
-- Does not support quantities of items
-- Technically unlimited
--
-- @param {Frame} frame
-- @return {number}
--------------------------------------------------------------------------------
function p.simple(frame)
	return simple(getArgs(frame), sum);
end

--------------------------------------------------------------------------------
-- For simple sets, 1 item at a time
-- Does not support quantities of items
-- Technically unlimited
--
-- @function p._simple
-- @param {string[]} items
-- @param {function} func
-- @return {number}
--------------------------------------------------------------------------------
function simple(items, func)
	local prices = {};
	for _, item in ipairs(items) do
		table.insert(prices, cvPrice(item));
	end
	return func(prices);
end
p._simple = simple;

--------------------------------------------------------------------------------
-- Sums the prices contained in `list`.
--
-- @function p._sumPrices
-- @param {number[]} list
-- @return {number}
--------------------------------------------------------------------------------
p._sumPrices = sum;

return p;