forked from libvips/lua-vips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
79 lines (63 loc) · 1.88 KB
/
init.lua
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- top include for lua-vips
local ffi = require "ffi"
local uv -- Lazy required
local vips_lib, old_cwd
if ffi.os == "Windows" then
local bin = module.dir .. '/' .. ffi.os .. "-" .. ffi.arch .. '/'
-- Workaround for LoadPackagedLibrary limitations on Windows
uv = require "uv"
old_cwd = uv.cwd()
uv.chdir(bin) -- Change working directory to the binaries directory
vips_lib = ffi.load("libvips-42.dll")
else
vips_lib = ffi.load("vips")
end
require "cdefs"
local result = vips_lib.vips_init("lua-vips")
if result ~= 0 then
local errstr = ffi.string(vips_lib.vips_error_buffer())
vips_lib.vips_error_clear()
error("unable to start up libvips: " .. errstr)
end
local vips = {
verror = require "verror",
version = require "version",
log = require "log",
gvalue = require "gvalue",
vobject = require "vobject",
voperation = require "voperation",
Image = require "Image_methods",
}
-- Change working directory to original if it was changed earlier
if old_cwd then
uv.chdir(old_cwd)
end
function vips.leak_set(leak)
vips_lib.vips_leak_set(leak)
end
function vips.cache_set_max(max)
vips_lib.vips_cache_set_max(max)
end
function vips.cache_get_max()
return vips_lib.vips_cache_get_max()
end
function vips.cache_set_max_files(max)
vips_lib.vips_cache_set_max_files(max)
end
function vips.cache_get_max_files()
return vips_lib.vips_cache_get_max_files()
end
function vips.cache_set_max_mem(max)
vips_lib.vips_cache_set_max_mem(max)
end
function vips.cache_get_max_mem()
return vips_lib.vips_cache_get_max_mem()
end
-- for compat with 1.1-6, when these were misnamed
vips.set_max = vips.cache_set_max
vips.get_max = vips.cache_get_max
vips.set_max_files = vips.cache_set_max_files
vips.get_max_files = vips.cache_get_max_files
vips.set_max_mem = vips.cache_set_max_mem
vips.get_max_mem = vips.cache_get_max_mem
return vips