Skip to content

Commit c681e15

Browse files
author
Rafael Gago
committed
ldbus: Allow specifying variant types for args
On the ldbus backend the function dbus.new_variant has been added. This allows overriding the variant type autodetection for types not expressable as arguments on the LUA type system, e.g. 'o', which gets translated to string. Note that this function gets available as dbus.raw.new_variant Example usage: local variant = dbus.raw.new_variant myvariant = { 'v', variant('aa{sv}', { { k1 = 'v1' }, --val is string variant (autodetected) { k2 = variant ('o', '/some/dbus/path')} }) }
1 parent 657f3d8 commit c681e15

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

awesome/dbus.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ for _, v in pairs (ldbus.basic_types) do
180180
dbus.set_of_basic_types[v] = true
181181
end
182182

183+
dbus.variant_mt = {}
184+
function dbus.new_variant(vtype, value)
185+
assert(value)
186+
vtype = vtype or dbus.type(value)
187+
return setmetatable ({ t = vtype, v = value }, dbus.variant_mt)
188+
end
189+
183190
function dbus.consume_type(dtype)
184191
if not dtype then
185192
return nil
@@ -230,7 +237,15 @@ function dbus.append_arg(iter, value, dbus_type)
230237
end
231238
iter:close_container(arr_iter)
232239
elseif dt == ldbus.types.variant then
233-
local val, var_dt = value, dbus.type(value)
240+
local val, var_dt
241+
if type(value) == "table" and
242+
getmetatable(value) == dbus.variant_mt then
243+
val = value.v
244+
var_dt = value.t
245+
else
246+
val = value
247+
var_dt = dbus.type(value)
248+
end
234249
local var_iter = iter:open_container(dt, var_dt)
235250
dbus.append_arg(var_iter, val, var_dt)
236251
iter:close_container(var_iter)

0 commit comments

Comments
 (0)