From 879d9ff2b8f80b7c8e4adadf0702154d9ae932f4 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Wed, 2 Sep 2015 11:24:29 +0000 Subject: uci:set_list: Delete option if the list is empty Allows lists fetched with get_list to be modified and simply passed back to set_list. Explicitly calling set_list() with an empty list is clearly requesting that there be zero list items, ie, deletion of the option altogether. Signed-off-by: Karl Palsson --- modules/luci-base/luasrc/model/uci.luadoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/luci-base/luasrc/model/uci.luadoc') diff --git a/modules/luci-base/luasrc/model/uci.luadoc b/modules/luci-base/luasrc/model/uci.luadoc index 80464f7cec..f3aa609d59 100644 --- a/modules/luci-base/luasrc/model/uci.luadoc +++ b/modules/luci-base/luasrc/model/uci.luadoc @@ -104,14 +104,15 @@ Get the given option from the first section with the given type. ]] ---[[ -Set given values as list. +Set given values as list. Setting a list option to an empty list +has the same effect as deleting the option. @class function @name Cursor.set_list @param config UCI config @param section UCI section name @param option UCI option -@param value UCI value +@param value value or table. Raw values will become a single item table. @return Boolean whether operation succeeded ]] -- cgit v1.2.3 From 03786ed853fb2d538bd3448f778e9d0cfe50691e Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Wed, 2 Sep 2015 15:18:13 +0000 Subject: uci:get_list: always return a table, no matter what. Previously, get_list("fake", "non-existent", "notreal") would still return a table, just empty. This is nice, as you can always iterate the returned table, without having to check it first. However, if you happened to pass a nil for any of the parameters, you would actually get a nil in return. This was inconsistent. The documentation is updated to clarify the behaviour of this function. Signed-off-by: Karl Palsson --- modules/luci-base/luasrc/model/uci.lua | 2 +- modules/luci-base/luasrc/model/uci.luadoc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/luci-base/luasrc/model/uci.luadoc') diff --git a/modules/luci-base/luasrc/model/uci.lua b/modules/luci-base/luasrc/model/uci.lua index e9bac6ec03..577c6cde08 100644 --- a/modules/luci-base/luasrc/model/uci.lua +++ b/modules/luci-base/luasrc/model/uci.lua @@ -111,7 +111,7 @@ function Cursor.get_list(self, config, section, option) local val = self:get(config, section, option) return ( type(val) == "table" and val or { val } ) end - return nil + return {} end function Cursor.get_first(self, conf, stype, opt, def) diff --git a/modules/luci-base/luasrc/model/uci.luadoc b/modules/luci-base/luasrc/model/uci.luadoc index f3aa609d59..9e4a58f1d9 100644 --- a/modules/luci-base/luasrc/model/uci.luadoc +++ b/modules/luci-base/luasrc/model/uci.luadoc @@ -88,7 +88,8 @@ Get an option or list and return values as table. @param config UCI config @param section UCI section name @param option UCI option -@return UCI value +@return table. If the option was not found, you will simply get +-- an empty table. ]] ---[[ -- cgit v1.2.3