| 1 | GLib 2.86 removed the GObject.TypeClass.ref() function, replacing it
|
| 2 | with GObject.TypeClass.get()—this commit makes it so .get() is used in
|
| 3 | GLib >= 2.86, while still preserving the old behaviour on GLib < 2.86.
|
| 4 |
|
| 5 | Upstream-Status: known issue <https://github.com/lgi-devs/lgi/issues/346>
|
| 6 | ---
|
| 7 | LuaGObject/ffi.lua | 15 ++++++++++++---
|
| 8 | 1 file changed, 12 insertions(+), 3 deletions(-)
|
| 9 |
|
| 10 | diff --git a/LuaGObject/ffi.lua b/LuaGObject/ffi.lua
|
| 11 | index 799f68e5..0695b0be 100644
|
| 12 | |
| 13 | |
| 14 | @@ -76,18 +76,27 @@ end
|
| 15 |
|
| 16 | -- Creates new enum/flags table with all values from specified gtype.
|
| 17 | function ffi.load_enum(gtype, name)
|
| 18 | - local GObject = core.repo.GObject
|
| 19 | + local GLib, GObject = core.repo.GLib, core.repo.GObject
|
| 20 | local is_flags = GObject.Type.is_a(gtype, GObject.Type.FLAGS)
|
| 21 | local enum_component = component.create(
|
| 22 | gtype, is_flags and enum.bitflags_mt or enum.enum_mt, name)
|
| 23 | - local type_class = GObject.TypeClass.ref(gtype)
|
| 24 | + local type_class
|
| 25 | + -- GLib >= 2.86 deprecates GObject.TypeClass.ref() in favour of .get()
|
| 26 | + if GLib.check_version(2, 86, 0) then
|
| 27 | + type_class = GObject.TypeClass.ref(gtype)
|
| 28 | + else
|
| 29 | + type_class = GObject.TypeClass.get(gtype)
|
| 30 | + end
|
| 31 | local enum_class = core.record.cast(
|
| 32 | type_class, is_flags and GObject.FlagsClass or GObject.EnumClass)
|
| 33 | for i = 0, enum_class.n_values - 1 do
|
| 34 | local val = core.record.fromarray(enum_class.values, i)
|
| 35 | enum_component[core.upcase(val.value_nick):gsub('%-', '_')] = val.value
|
| 36 | end
|
| 37 | - type_class:unref()
|
| 38 | + -- For GLib versions below 2.86, type_class was ref'd and needs to be unref'd
|
| 39 | + if GLib.check_version(2, 86, 0) then
|
| 40 | + type_class:unref()
|
| 41 | + end
|
| 42 | return enum_component
|
| 43 | end
|
| 44 |
|