aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-03-15 15:07:16 +0100
committerKim Alvefur <zash@zash.se>2017-03-15 15:07:16 +0100
commit911bea77466363a8bfcc01b1ebc689089d810efe (patch)
tree6ab98da1f84c57b5f72a37be38cddae6762cef46 /core
parentdf4695718555a55582503b8086d530241c2e1d0f (diff)
downloadprosody-911bea77466363a8bfcc01b1ebc689089d810efe.tar.gz
prosody-911bea77466363a8bfcc01b1ebc689089d810efe.zip
core.moduleapi: Factor out code for getting a scalar config option
Diffstat (limited to 'core')
-rw-r--r--core/moduleapi.lua23
1 files changed, 8 insertions, 15 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 34214f26..7d954c1f 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -213,7 +213,7 @@ function api:get_option(name, default_value)
return value;
end
-function api:get_option_string(name, default_value)
+function api:get_option_scalar(name, default_value)
local value = self:get_option(name, default_value);
if type(value) == "table" then
if #value > 1 then
@@ -221,6 +221,11 @@ function api:get_option_string(name, default_value)
end
value = value[1];
end
+ return value;
+end
+
+function api:get_option_string(name, default_value)
+ local value = self:get_option_scalar(name, default_value);
if value == nil then
return nil;
end
@@ -228,13 +233,7 @@ function api:get_option_string(name, default_value)
end
function api:get_option_number(name, ...)
- local value = self:get_option(name, ...);
- if type(value) == "table" then
- if #value > 1 then
- self:log("error", "Config option '%s' does not take a list, using just the first item", name);
- end
- value = value[1];
- end
+ local value = self:get_option_scalar(name, ...);
local ret = tonumber(value);
if value ~= nil and ret == nil then
self:log("error", "Config option '%s' not understood, expecting a number", name);
@@ -243,13 +242,7 @@ function api:get_option_number(name, ...)
end
function api:get_option_boolean(name, ...)
- local value = self:get_option(name, ...);
- if type(value) == "table" then
- if #value > 1 then
- self:log("error", "Config option '%s' does not take a list, using just the first item", name);
- end
- value = value[1];
- end
+ local value = self:get_option_scalar(name, ...);
if value == nil then
return nil;
end