Skip to content

Commit 54d90bf

Browse files
committed
Fix GLib 2.86 regression
GLib 2.86 removed the GObject.TypeClass.ref() function, replacing it with GObject.TypeClass.get()—this commit makes it so .get() is used in GLib >= 2.86, while still preserving the old behaviour on GLib < 2.86.
1 parent adde759 commit 54d90bf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

LuaGObject/ffi.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,27 @@ end
7676

7777
-- Creates new enum/flags table with all values from specified gtype.
7878
function ffi.load_enum(gtype, name)
79-
local GObject = core.repo.GObject
79+
local GLib, GObject = core.repo.GLib, core.repo.GObject
8080
local is_flags = GObject.Type.is_a(gtype, GObject.Type.FLAGS)
8181
local enum_component = component.create(
8282
gtype, is_flags and enum.bitflags_mt or enum.enum_mt, name)
83-
local type_class = GObject.TypeClass.ref(gtype)
83+
local type_class
84+
-- GLib >= 2.86 deprecates GObject.TypeClass.ref() in favour of .get()
85+
if GLib.check_version(2, 86, 0) then
86+
type_class = GObject.TypeClass.ref(gtype)
87+
else
88+
type_class = GObject.TypeClass.get(gtype)
89+
end
8490
local enum_class = core.record.cast(
8591
type_class, is_flags and GObject.FlagsClass or GObject.EnumClass)
8692
for i = 0, enum_class.n_values - 1 do
8793
local val = core.record.fromarray(enum_class.values, i)
8894
enum_component[core.upcase(val.value_nick):gsub('%-', '_')] = val.value
8995
end
90-
type_class:unref()
96+
-- For GLib versions below 2.86, type_class was ref'd and needs to be unref'd
97+
if GLib.check_version(2, 86, 0) then
98+
type_class:unref()
99+
end
91100
return enum_component
92101
end
93102

0 commit comments

Comments
 (0)