forked from libvips/lua-vips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.lua
More file actions
55 lines (44 loc) · 1.38 KB
/
Connection.lua
File metadata and controls
55 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- abstract base Connection class
local ffi = require "ffi"
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
Connection.new = function(vconnection)
local connection = {}
connection.vconnection = vobject.new(vconnection)
return setmetatable(connection, Connection.mt)
end
function Connection_method:vobject()
return ffi.cast(vobject.typeof, self.vconnection)
end
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.vconnection)
local filename = vips_lib.vips_connection_filename(so)
if filename == ffi.NULL then
return nil
else
return ffi.string(filename)
end
end
function Connection_method:nick()
-- Make a human-readable name for a connection suitable for error messages.
local so = ffi.cast('VipsConnection *', self.vconnection)
local nick = vips_lib.vips_connection_nick(so)
if nick == ffi.NULL then
return nil
else
return ffi.string(nick)
end
end
return ffi.metatype("VipsConnection", {
__index = Connection
})