# HG changeset patch # User Kim Alvefur # Date 1489586836 -3600 # Node ID c64ddee9d67161f4b4f293aa87340772cd1b9d4b # Parent 703f7f45feb4de9390639a77229054258aa77ded core.moduleapi: Factor out code for getting a scalar config option diff -r 703f7f45feb4 -r c64ddee9d671 core/moduleapi.lua --- a/core/moduleapi.lua Sun Mar 12 12:49:34 2017 +0100 +++ b/core/moduleapi.lua Wed Mar 15 15:07:16 2017 +0100 @@ -213,7 +213,7 @@ 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 @@ 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 @@ 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 @@ 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