lua-dbus icon indicating copy to clipboard operation
lua-dbus copied to clipboard

Can't specify a type for variants

Open bartbes opened this issue 9 years ago • 2 comments

The current code, at least for ldbus, seems to derive the actual type of a variant at runtime. This however means certain types, in particular numerical types, cannot be expressed. Additionally, considering properties are implemented with a Get that returns a variant, properties aren't actually of the type they claim to be, nor are they ever typechecked.

bartbes avatar Feb 14 '16 21:02 bartbes

For now I've monkeypatched it in my own code using the following:

        local orig_append = luadbus.raw.append_arg
        function luadbus.raw.append_arg(iter, value, typ, subtyp)
                if typ == "v" and type(value) == "function" then
                        value, subtyp = value()
                        local subiter = iter:open_container("v", subtyp)
                        luadbus.raw.append_arg(subiter, value, subtyp)
                        iter:close_container(subiter)
                        return
                end
                return orig_append(iter, value, typ, subtyp)
        end

This allows a variant to be a function, returning the value then the type. Not the cleanest solution, but it works for now. Of course it still requires things like the Properties interface to be updated, or the read function returning such a functio

bartbes avatar Feb 15 '16 12:02 bartbes

This project is dead, but for anyone still using this and some other things on the dbus backend are fixed in: https://github.com/dodo/lua-dbus/pull/5

RafaGago avatar Feb 14 '18 12:02 RafaGago