Skip to content

Commit b81afde

Browse files
committed
fixup Connection
1 parent 1d34228 commit b81afde

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

example/target.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local vips = require "vips"
22

33
if #arg ~= 2 then
4-
error("Usage: lua test.lua ~/pics/k2.png .avif > x")
4+
error("Usage: lua target.lua ~/pics/k2.png .avif > x")
55
end
66

77
local infilename = arg[1]

src/vips/Connection.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@ local vobject = require "vips.vobject"
66

77
local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips")
88

9-
local Connection = {}
9+
local Connection_method = {}
1010

11-
Connection.vobject = function(self)
12-
return ffi.cast(vobject.typeof, self)
11+
local Connection = {
12+
mt = {
13+
__index = Connection_method,
14+
}
15+
}
16+
17+
function Connection.mt:__tostring()
18+
return self:filename() or self:nick() or "(nil)"
1319
end
1420

15-
Connection.new = function(self)
16-
return vobject.new(self)
21+
Connection.new = function(vconnection)
22+
local connection = {}
23+
connection.vconnection = vobject.new(vconnection)
24+
return setmetatable(connection, Connection.mt)
1725
end
18-
Connection.filename = function(self)
26+
function Connection_method:filename()
1927
-- Get the filename asscoiated with a connection. Return nil if there is no associated file.
20-
local so = ffi.cast('VipsConnection *', self.pointer)
28+
local so = ffi.cast('VipsConnection *', self.vconnection)
2129
local filename = vips_lib.vips_connection_filename(so)
2230
if filename == ffi.NULL then
2331
return nil
@@ -26,10 +34,10 @@ Connection.filename = function(self)
2634
end
2735
end
2836

29-
Connection.nick = function(self)
37+
function Connection_method:nick()
3038
-- Make a human-readable name for a connection suitable for error messages.
3139

32-
local so = ffi.cast('VipsConnection *', self.pointer)
40+
local so = ffi.cast('VipsConnection *', self.vconnection)
3341
local nick = vips_lib.vips_connection_nick(so)
3442
if nick == ffi.NULL then
3543
return nil

src/vips/Image_methods.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function Image_method:write_to_target(target, format_string, ...)
430430
error(verror.get())
431431
end
432432

433-
return voperation.call(ffi.string(name), options, self, target, unpack { ... })
433+
return voperation.call(ffi.string(name), options, self, target.vconnection, unpack { ... })
434434
end
435435
-- get/set metadata
436436

0 commit comments

Comments
 (0)