forked from libvips/lua-vips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarget.lua
More file actions
46 lines (38 loc) · 1.18 KB
/
Target.lua
File metadata and controls
46 lines (38 loc) · 1.18 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
-- An input connection
local ffi = require "ffi"
local Connection = require "vips.Connection"
local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips")
local Target = {}
Target.new_to_descriptor = function(descriptor)
collectgarbage("stop")
local target = vips_lib.vips_target_new_to_descriptor(descriptor)
collectgarbage("restart")
if target == ffi.NULL then
error("can't create output target from descriptor " .. descriptor)
else
return Connection.new(target)
end
end
Target.new_to_file = function(filename)
collectgarbage("stop")
local target = vips_lib.vips_target_new_to_file(filename)
collectgarbage("restart")
if target == ffi.NULL then
error("can't create output target from filename " .. filename)
else
return Connection.new(target)
end
end
Target.new_to_memory = function()
collectgarbage("stop")
local target = vips_lib.vips_target_new_to_memory()
collectgarbage("restart")
if target == ffi.NULL then
error("can't create output target from memory")
else
return Connection.new(target)
end
end
return ffi.metatype("VipsTarget", {
__index = Target
})