-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extend set_property? #3
Comments
Not entirely correct. Looking at your suggested code, you would like to allow the caller to pass either a Do you have some examples where more complex properties can be set? If that's the case, we could look into adding a |
If I am stumbling upon an example, I'll give feedback - currently I can't remember where I had that problem. The main reason I mentioned it was: It returns plain Lua types (without signature-value table).
Maybe I am using it completely wrong and maybe I am missing something but I just can't do: local dev = NetworkManager(nm:GetDeviceByIpIface(devicename),"$.Device")
dev.Managed = true
dev.Autoconnect = true (which, in my understanding, will be a real auto conversion by basic type) - it's complaining that "opts" is not a table. I have to pass a table with "signature" and "value" local dev = NetworkManager(nm:GetDeviceByIpIface(devicename),"$.Device")
dev.Managed = { signature = "b", value = true }
dev.Autoconnect = { signature = "b", value = true } That's why I mentioned: set_property does no auto conversion from basic types. lua-dbus_proxy/src/dbus_proxy/_proxy.lua Line 259 in dacbc56
my understanding seems to be correct. I can only pass a table with "signature" and "value" or I get an error. A really nice version of set_property would be something like (be careful, untested copied code): local function set_property(proxy, name, opts)
local variant_value
local vtype = type(opts)
if vtype == "boolean" then
variant_value = GVariant("b",opts)
elseif vtype == "string" then
variant_type = GVariant("s",opts)
elseif vtype == "number" then
variant_type = GVariant("u",opts)
elseif vtype == "userdata" and tostring(opts):find("GLib%.Variant$") then
variant_value = opts
elseif vtype == "table" and opts.signature and opts.value then
variant_value = GVariant(opts.signature, opts.value)
else
error("Wrong parameter, should be table with { .signature and .value } or GVariant")
end
proxy._proxy:set_cached_property(name, variant_value)
end That would be awesome and really auto converts basic types AND gives the possibility to pass complex GVariants.
One part is: it doesn't throw an error if I doesn't pass a table to the property. That took some time to understand: ok, no basic types possible (as I get them via get_property). The other part is: when it should be opaque (and equal), let get_property also return a table with {signature = "...", value = "..."}?
I made a mistake mixing some things - The real complex types and problems I had was when I called a method on NetworkManager (GetSettings() and Update(settings)), not on properties. |
OK, I see your point more clearly now. Thanks for taking time to explain everything. To recap:
So, regarding Also, Lua strings could be DBus's strings, signatures or object paths. There should be some functionality in And there are container types too: struct, array, dict... So, our step zero would be to have a basic mapping by "reversing" what happens in References: DBus funtionality from |
I'll take a look at _variant.strip and give response here. |
In _proxy.lua, the getter's and setter's are not as intuitive as they should be.
get_property returns some sort of Lua'ized version of the result where some of the GVariants are translated to plain Lua.
set_property does nothing like auto conversion to GVariant.
Maybe a minimum solution would be something like:
This may report a correct error and also accepts GVariants if they are passed.
It may also be nice to have a converter for the basic types (number, string) but that's just an idea.
What do you think?
The text was updated successfully, but these errors were encountered: