@@ -6,18 +6,26 @@ local vobject = require "vips.vobject"
6
6
7
7
local vips_lib = ffi .load (ffi .os == " Windows" and " libvips-42.dll" or " vips" )
8
8
9
- local Connection = {}
9
+ local Connection_method = {}
10
10
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)"
13
19
end
14
20
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 )
17
25
end
18
- Connection . filename = function ( self )
26
+ function Connection_method : filename ( )
19
27
-- 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 )
21
29
local filename = vips_lib .vips_connection_filename (so )
22
30
if filename == ffi .NULL then
23
31
return nil
@@ -26,10 +34,10 @@ Connection.filename = function(self)
26
34
end
27
35
end
28
36
29
- Connection . nick = function ( self )
37
+ function Connection_method : nick ( )
30
38
-- Make a human-readable name for a connection suitable for error messages.
31
39
32
- local so = ffi .cast (' VipsConnection *' , self .pointer )
40
+ local so = ffi .cast (' VipsConnection *' , self .vconnection )
33
41
local nick = vips_lib .vips_connection_nick (so )
34
42
if nick == ffi .NULL then
35
43
return nil
0 commit comments