Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions lgi/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,33 @@ end

-- Creates new enum/flags table with all values from specified gtype.
function ffi.load_enum(gtype, name)
local GObject = core.repo.GObject
local GLib, GObject = core.repo.GLib, core.repo.GObject
local is_flags = GObject.Type.is_a(gtype, GObject.Type.FLAGS)
local enum_component = component.create(
gtype, is_flags and enum.bitflags_mt or enum.enum_mt, name)
local type_class = GObject.TypeClass.ref(gtype)
local type_class
-- GLib >= 2.86 deprecates GObject.TypeClass.ref() in favour of .get()
if GLib.check_version(2, 86, 0) then
type_class = GObject.TypeClass.ref(gtype)
else
type_class = GObject.TypeClass.get(gtype)
end
local enum_class = core.record.cast(
type_class, is_flags and GObject.FlagsClass or GObject.EnumClass)
for i = 0, enum_class.n_values - 1 do
local val = core.record.fromarray(enum_class.values, i)
enum_component[core.upcase(val.value_nick):gsub('%-', '_')] = val.value
if GLib.check_version(2, 87, 0) then
for i = 0, enum_class.n_values - 1 do
local val = core.record.fromarray(enum_class.values, i)
enum_component[core.upcase(val.value_nick):gsub('%-', '_')] = val.value
end
else
for _, val in ipairs(enum_class.values) do
enum_component[core.upcase(val.value_nick):gsub('%-', '_')] = val.value
end
end
-- For GLib versions below 2.86, type_class was ref'd and needs to be unref'd
if GLib.check_version(2, 86, 0) then
type_class:unref()
end
type_class:unref()
return enum_component
end

Expand Down
10 changes: 8 additions & 2 deletions tests/pango.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ function pango.glyphstring()
local offset = items[i].offset
local length = items[i].length
local analysis = items[i].analysis
local pgs = Pango.GlyphString()
Pango.shape(string.sub(s,1+offset), length, analysis, pgs)
local pgs
if Pango.version_check(1, 56, 2) then
pgs = Pango.GlyphString()
Pango.shape(string.sub(s,1+offset), length, analysis, pgs)
else
pgs = Pango.shape(string.sub(s,1+offset), length, analysis)
end

-- Pull out individual glyphs with pgs.glyphs
local glyphs = pgs.glyphs
check(type(glyphs) == 'table')
Expand Down
12 changes: 9 additions & 3 deletions tests/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
--]]--------------------------------------------------------------------------

local lgi = require 'lgi'
local core = require 'lgi.core'
local GObject = lgi.GObject
local Gio = lgi.Gio
local GLib = lgi.GLib

Expand Down Expand Up @@ -44,8 +46,12 @@ function progress.file_copy()
check_gerror(Gio.File, 'copy_finish', self, result)
loop:quit()
end

src:copy_async(dst, flags, priority, cancellable,
progress_callback, finish_callback)
if core.repo.GLib.check_version(2, 82, 0) then
src:copy_async(dst, flags, priority, cancellable,
progress_callback, finish_callback)
else
src:copy_async(dst, flags, priority, cancellable,
GObject.Closure(progress_callback), GObject.Closure(finish_callback))
end
loop:run()
end
Loading