Module:Utils: Difference between revisions
m todo??? |
Fix for clamp. Improve documentation |
||
| Line 19: | Line 19: | ||
-- Clamp function | -- Clamp function | ||
-- Underscore-prefixed in case a wrapper for a template is ever needed | -- Underscore-prefixed in case a wrapper for a template is ever needed | ||
function p._clamp( | function p._clamp(value, min_value, max_value) | ||
return math.min(math.max(value, | return math.min(math.max(value, min_value), max_value) | ||
end | end | ||
| Line 72: | Line 72: | ||
end | end | ||
-- | -- Parse a ratio string like "3/2" into a number | ||
-- Use default on error; cannot be used with {{#invoke:}} | |||
function p.eval_num_arg(input, def_value) | function p.eval_num_arg(input, def_value) | ||
local result = input | local result = input | ||