lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
440 stars 70 forks source link

`GLib.Variant: no 'n'` when using `GLib.Variant("(av)", ...)` #315

Open Delta-official opened 9 months ago

Delta-official commented 9 months ago

I get the following error:

2024-01-23 23:28:50 E: awesome: Error during a protected call: /usr/share/lua/5.4/lgi/override/GLib-Variant.lua:141: GLib.Variant: no 'n'
stack traceback:
    [C]: in function 'error'
    /usr/share/lua/5.4/lgi/component.lua:160: in function </usr/share/lua/5.4/lgi/component.lua:156>
    [C]: in metamethod 'index'
    /usr/share/lua/5.4/lgi/override/GLib-Variant.lua:141: in upvalue 'variant_new'
    /usr/share/lua/5.4/lgi/override/GLib-Variant.lua:159: in upvalue 'variant_new'
    /usr/share/lua/5.4/lgi/override/GLib-Variant.lua:176: in function </usr/share/lua/5.4/lgi/override/GLib-Variant.lua:170>
    (...tail calls...)
    /home/delta/.config/awesome/curious.lua:87: in function </home/delta/.config/awesome/curious.lua:81>
    [C]: in function 'xpcall'
    /usr/share/awesome/lib/gears/protected_call.lua:41: in function </usr/share/awesome/lib/gears/protected_call.lua:40>
    (...tail calls...)
    /home/delta/.config/awesome/curious.lua:92: in upvalue 'target'
    /usr/share/lua/5.4/lgi/override/GObject-Closure.lua:286: in function </usr/share/lua/5.4/lgi/override/GObject-Closure.lua:283>

When using this piece of code:

-- ...
local builder = GLib.VariantBuilder(GLib.VariantType("av"))
serialize(builder, { "test", some_key = "some_value" }) -- constructs a fully valid variant array
invocation:return_value(GLib.Variant("(av)", { builder }))
-- ...

(Sidenote: It seems that even if it didn't fail, it would be inefficient as for some reason the variant_new function doesn't make the distinction between a lua table and a Variant)