Skip to content

Commit

Permalink
fixup Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandlo committed Dec 24, 2024
1 parent 1d34228 commit b81afde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example/target.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local vips = require "vips"

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

local infilename = arg[1]
Expand Down
26 changes: 17 additions & 9 deletions src/vips/Connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ local vobject = require "vips.vobject"

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

local Connection = {}
local Connection_method = {}

Connection.vobject = function(self)
return ffi.cast(vobject.typeof, self)
local Connection = {
mt = {
__index = Connection_method,
}
}

function Connection.mt:__tostring()
return self:filename() or self:nick() or "(nil)"
end

Connection.new = function(self)
return vobject.new(self)
Connection.new = function(vconnection)
local connection = {}
connection.vconnection = vobject.new(vconnection)
return setmetatable(connection, Connection.mt)
end
Connection.filename = function(self)
function Connection_method:filename()
-- Get the filename asscoiated with a connection. Return nil if there is no associated file.
local so = ffi.cast('VipsConnection *', self.pointer)
local so = ffi.cast('VipsConnection *', self.vconnection)
local filename = vips_lib.vips_connection_filename(so)
if filename == ffi.NULL then
return nil
Expand All @@ -26,10 +34,10 @@ Connection.filename = function(self)
end
end

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

local so = ffi.cast('VipsConnection *', self.pointer)
local so = ffi.cast('VipsConnection *', self.vconnection)
local nick = vips_lib.vips_connection_nick(so)
if nick == ffi.NULL then
return nil
Expand Down
2 changes: 1 addition & 1 deletion src/vips/Image_methods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function Image_method:write_to_target(target, format_string, ...)
error(verror.get())
end

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

Expand Down

0 comments on commit b81afde

Please sign in to comment.