diff options
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | core/features.lua | 1 | ||||
-rw-r--r-- | core/moduleapi.lua | 16 |
3 files changed, 16 insertions, 2 deletions
@@ -41,6 +41,7 @@ TRUNK ### Module API - Config interface API can require that string values be picked from a provided set +- Acceptable interval can be specified for number options ## Changes diff --git a/core/features.lua b/core/features.lua index 2948a1a7..41d8ce70 100644 --- a/core/features.lua +++ b/core/features.lua @@ -18,5 +18,6 @@ return { -- new moduleapi methods "getopt-enum"; + "getopt-interval"; }; }; diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 68818b8d..87a25ae7 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -232,12 +232,24 @@ function api:get_option_string(name, default_value) return tostring(value); end -function api:get_option_number(name, ...) - local value = self:get_option_scalar(name, ...); +function api:get_option_number(name, default_value, min, max) + local value = self:get_option_scalar(name, default_value); local ret = tonumber(value); if value ~= nil and ret == nil then self:log("error", "Config option '%s' not understood, expecting a number", name); end + if ret == default_value then + -- skip interval checks for default or nil + return ret; + end + if min and ret < min then + self:log("warn", "Config option '%s' out of bounds %g < %g", name, ret, min); + return min; + end + if max and ret > max then + self:log("warn", "Config option '%s' out of bounds %g > %g", name, ret, max); + return max; + end return ret; end |