Skip to content

Commit

Permalink
Simplify Connection class
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandlo committed Feb 5, 2025
1 parent 5a84eca commit 8a11241
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/vips/Connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@ local vobject = require "vips.vobject"

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

local Connection_method = {}

local Connection = {
mt = {
__index = Connection_method,
}
}

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

Connection.new = function(vconnection)
local connection = {}
connection.vconnection = vobject.new(vconnection)
return setmetatable(connection, Connection.mt)
end
function Connection_method:vobject()
function Connection:vobject()
return ffi.cast(vobject.typeof, self.vconnection)
end

function Connection_method:filename()
function Connection:filename()
-- Get the filename asscoiated with a connection. Return nil if there is no associated file.
local so = ffi.cast('VipsConnection *', self.vconnection)
local filename = vips_lib.vips_connection_filename(so)
Expand All @@ -38,7 +28,7 @@ function Connection_method:filename()
end
end

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

local so = ffi.cast('VipsConnection *', self.vconnection)
Expand All @@ -51,5 +41,8 @@ function Connection_method:nick()
end

return ffi.metatype("VipsConnection", {
__index = Connection
__index = Connection,
__tostring = function(self)
return self:filename() or self:nick() or "(nil)"
end
})

0 comments on commit 8a11241

Please sign in to comment.