Skip to content
Open
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
14 changes: 10 additions & 4 deletions lgi/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,22 @@ 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 enum_class = core.record.cast(
type_class, is_flags and GObject.FlagsClass or GObject.EnumClass)
for i = 0, enum_class.n_values - 1 do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should do this only for (GLib.MAJOR_VERSION, GLib.MINOR_VERSION) >= (2, 87) (adjusting the syntax)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have picked your commit here

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
type_class:unref()
return enum_component
Expand Down