Skip to content

Commit 8a11241

Browse files
committed
Simplify Connection class
1 parent 5a84eca commit 8a11241

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/vips/Connection.lua

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,18 @@ 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_method = {}
10-
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)"
19-
end
9+
local Connection = {}
2010

2111
Connection.new = function(vconnection)
2212
local connection = {}
2313
connection.vconnection = vobject.new(vconnection)
2414
return setmetatable(connection, Connection.mt)
2515
end
26-
function Connection_method:vobject()
16+
function Connection:vobject()
2717
return ffi.cast(vobject.typeof, self.vconnection)
2818
end
2919

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

41-
function Connection_method:nick()
31+
function Connection:nick()
4232
-- Make a human-readable name for a connection suitable for error messages.
4333

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

5343
return ffi.metatype("VipsConnection", {
54-
__index = Connection
44+
__index = Connection,
45+
__tostring = function(self)
46+
return self:filename() or self:nick() or "(nil)"
47+
end
5548
})

0 commit comments

Comments
 (0)