Skip to content

Commit 6c10316

Browse files
committed
Add bitops module
Currently only bit.band is needed. For LuaJIT: use builtin bit.band For Lua 5.1, 5.2: use bit.band from luabitop if available For Lua 5.3, 5.4: use builtin & operator
1 parent e0bdc2d commit 6c10316

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lua-vips-1.1-10.rockspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ build = {
2424
type = "builtin",
2525
modules = {
2626
vips = "src/vips.lua",
27+
["vips.bitops"] = "src/vips/bitops.lua",
2728
["vips.cdefs"] = "src/vips/cdefs.lua",
2829
["vips.verror"] = "src/vips/verror.lua",
2930
["vips.version"] = "src/vips/version.lua",

src/vips/bitops.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local hasbit, bit = pcall(require, "bit")
2+
local bitops = {}
3+
4+
if hasbit then -- Lua 5.1, 5.2 with luabitop or LuaJIT
5+
bitops.band = bit.band
6+
elseif (_VERSION == "Lua 5.1" or _VERSION == "Lua 5.2") then
7+
error("Bit operations missing. Please install 'luabitop'")
8+
else -- Lua >= 5.3
9+
local band, err = load("return function(a, b) return a & b end")
10+
if band then
11+
local ok
12+
ok, bitops.band = pcall(band)
13+
if not ok then
14+
error("Execution error")
15+
end
16+
else
17+
error("Compilation error" .. err)
18+
end
19+
end
20+
21+
return bitops

src/vips/voperation.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
-- lookup and call operations
33

44
local ffi = require "ffi"
5-
local bit = require "bit"
65

6+
local bitops = require "vips.bitops"
77
local verror = require "vips.verror"
88
local version = require "vips.version"
99
local log = require "vips.log"
1010
local gvalue = require "vips.gvalue"
1111
local vobject = require "vips.vobject"
1212
local Image = require "vips.Image"
1313

14-
local band = bit.band
14+
local band = bitops.band
1515
local type = type
1616
local error = error
1717
local pairs = pairs

0 commit comments

Comments
 (0)