From cd40a5edfc72f2abd26de3f8be34c3f48a4b4897 Mon Sep 17 00:00:00 2001
From: Victoria Lacroix <victoria@vtrlx.ca>
Date: Wed, 4 Feb 2026 14:12:03 -0500
Subject: [PATCH] ffi: conform load_enum to GLib 2.87.0

GLib 2.87.0 includes a fix
(https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4803) to how enum
values are handled, causing the value to be read as a Lua table instead
of a GLib array. This requires some slightly tweaked code when loading
an enum.
---
 LuaGObject/ffi.lua | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/LuaGObject/ffi.lua b/LuaGObject/ffi.lua
index 62ecffb3..e8912f95 100644
--- a/lgi/ffi.lua
+++ b/lgi/ffi.lua
@@ -86,9 +86,15 @@ function ffi.load_enum(gtype, name)
    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

