--[[ @brief Sums all elements in a table.
     @param t A table of numbers.
     @return The total sum of all numbers in t.
--]]

function module.Sum(t, n)
	local sum = 0;
	if n then
		for i = 1, n do
			sum = sum + t[i>#t and #t or i] or 0;
		end
	else
		for i, v in pairs(t) do
			sum = sum + v;
		end
	end
	return sum;
end
