uci:get_list: always return a table, no matter what. 464/head
authorKarl Palsson <karlp@remake.is>
Wed, 2 Sep 2015 15:18:13 +0000 (15:18 +0000)
committerKarl Palsson <karlp@remake.is>
Wed, 2 Sep 2015 15:28:02 +0000 (15:28 +0000)
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 <karlp@remake.is>
modules/luci-base/luasrc/model/uci.lua
modules/luci-base/luasrc/model/uci.luadoc

index e9bac6e..577c6cd 100644 (file)
@@ -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
                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)
 end
 
 function Cursor.get_first(self, conf, stype, opt, def)
index f3aa609..9e4a58f 100644 (file)
@@ -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
 @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.
 ]]
 
 ---[[
 ]]
 
 ---[[