Skip to content

Commit 31f0287

Browse files
committed
Fix gtype for Lua5.1 on Windows
1 parent 1cccc4b commit 31f0287

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/vips/gvalue.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ gvalue.blob_type = gobject_lib.g_type_from_name("VipsBlob")
5656
gvalue.band_format_type = gobject_lib.g_type_from_name("VipsBandFormat")
5757
gvalue.blend_mode_type = version.at_least(8, 6) and gobject_lib.g_type_from_name("VipsBlendMode") or 0
5858

59+
-- gvalue.*_type can be of type cdata or number depending on the OS and Lua version
60+
-- gtypes as returned by vips_lib can also be of type cdata or number
61+
-- cdata and number are not comparable with Standard Lua (using luaffi-tkl)
62+
gvalue.comparable_type = type(gvalue.gdouble_type) == "number" and
63+
function(gtype) return tonumber(gtype) end or
64+
function(gtype) return gtype end
5965
gvalue.to_enum = function(gtype, value)
6066
-- turn a string into an int, ready to be passed into libvips
6167
local enum_value
@@ -84,7 +90,7 @@ end
8490

8591
gvalue.set = function(gv, value)
8692
local gtype_raw = gv.gtype
87-
local gtype = tonumber(gtype_raw)
93+
local gtype = gvalue.comparable_type(gtype_raw)
8894
local fundamental = gobject_lib.g_type_fundamental(gtype_raw)
8995

9096
if gtype == gvalue.gbool_type then
@@ -156,7 +162,7 @@ end
156162

157163
gvalue.get = function(gv)
158164
local gtype_raw = gv.gtype
159-
local gtype = tonumber(gtype_raw)
165+
local gtype = gvalue.comparable_type(gtype_raw)
160166
local fundamental = gobject_lib.g_type_fundamental(gtype_raw)
161167

162168
local result

src/vips/voperation.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ end
7373
voperation.set = function(self, name, flags, match_image, value)
7474
local vob = self:vobject()
7575
local gtype_raw = vob:get_typeof(name)
76-
local gtype = tonumber(gtype_raw)
76+
local gtype = gvalue.comparable_type(gtype_raw)
7777

7878
-- if the object wants an image and we have a constant, imageize it
7979
--

0 commit comments

Comments
 (0)