summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-07-26 22:13:38 +0200
committerJo-Philipp Wich <jo@mein.io>2018-07-27 14:07:23 +0200
commit9ead1e29a6404c5ba3a438a3f8a68b6a3dcaee3f (patch)
tree07cef082269ec3915634023070f313e4ffab8d1f
parentddf4c2b61733acacde4a48b9ccff353b101e54b2 (diff)
luci-base: utils: support multiple return values in util.ubus()
This is needed to deal with ubus methods that return multiple results, e.g. session/list Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--modules/luci-base/luasrc/util.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/modules/luci-base/luasrc/util.lua b/modules/luci-base/luasrc/util.lua
index 10428b0b3..f16b3afb2 100644
--- a/modules/luci-base/luasrc/util.lua
+++ b/modules/luci-base/luasrc/util.lua
@@ -16,7 +16,7 @@ local _ubus = require "ubus"
local _ubus_connection = nil
local getmetatable, setmetatable = getmetatable, setmetatable
-local rawget, rawset, unpack = rawget, rawset, unpack
+local rawget, rawset, unpack, select = rawget, rawset, unpack, select
local tostring, type, assert, error = tostring, type, assert, error
local ipairs, pairs, next, loadstring = ipairs, pairs, next, loadstring
local require, pcall, xpcall = require, pcall, xpcall
@@ -647,6 +647,17 @@ local ubus_codes = {
"CONNECTION_FAILED"
}
+local function ubus_return(...)
+ if select('#', ...) == 2 then
+ local rv, err = select(1, ...), select(2, ...)
+ if rv == nil and type(err) == "number" then
+ return nil, err, ubus_codes[err]
+ end
+ end
+
+ return ...
+end
+
function ubus(object, method, data)
if not _ubus_connection then
_ubus_connection = _ubus.connect()
@@ -657,8 +668,7 @@ function ubus(object, method, data)
if type(data) ~= "table" then
data = { }
end
- local rv, err = _ubus_connection:call(object, method, data)
- return rv, err, ubus_codes[err]
+ return ubus_return(_ubus_connection:call(object, method, data))
elseif object then
return _ubus_connection:signatures(object)
else