Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bitops #69

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
luaVersion: ["5.3", "5.4", "luajit-2.1.0-beta3", "luajit-openresty"]
luaVersion: ["5.1", "5.2", "5.3", "5.4", "luajit-2.1.0-beta3", "luajit-openresty"]

steps:
- uses: actions/checkout@v4
Expand All @@ -28,6 +28,9 @@ jobs:
run: |
make dev
if [[ ${{ matrix.luaVersion }} == 5.* ]]; then make ffi; fi
if [[ ${{ matrix.luaVersion }} == 5.1 ]] || [[ ${{ matrix.luaVersion }} == 5.2 ]]; then
make bit
fi

- name: Lint with luacheck
run: |
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DEV_ROCKS = "busted 2.2.0" "luacheck 1.1.2"
BUSTED_ARGS ?= -o gtest -v
TEST_CMD ?= busted $(BUSTED_ARGS)

.PHONY: dev ffi lint test
.PHONY: dev ffi bit lint test

dev:
@for rock in $(DEV_ROCKS) ; do \
Expand All @@ -17,6 +17,9 @@ dev:
ffi:
@luarocks install luaffi-tkl

bit:
@luarocks install luabitop

lint:
@luacheck -q .

Expand Down
1 change: 1 addition & 0 deletions lua-vips-1.1-10.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ build = {
type = "builtin",
modules = {
vips = "src/vips.lua",
["vips.bitops"] = "src/vips/bitops.lua",
["vips.cdefs"] = "src/vips/cdefs.lua",
["vips.verror"] = "src/vips/verror.lua",
["vips.version"] = "src/vips/version.lua",
Expand Down
21 changes: 21 additions & 0 deletions src/vips/bitops.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local hasbit, bit = pcall(require, "bit")
local bitops = {}

if hasbit then -- Lua 5.1, 5.2 with luabitop or LuaJIT
bitops.band = bit.band
elseif (_VERSION == "Lua 5.1" or _VERSION == "Lua 5.2") then
error("Bit operations missing. Please install 'luabitop'")
else -- Lua >= 5.3
local band, err = load("return function(a, b) return a & b end")
if band then
local ok
ok, bitops.band = pcall(band)
if not ok then
error("Execution error")
end
else
error("Compilation error" .. err)
end
end

return bitops
4 changes: 2 additions & 2 deletions src/vips/voperation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
-- lookup and call operations

local ffi = require "ffi"
local bit = require "bit"

local bitops = require "vips.bitops"
local verror = require "vips.verror"
local version = require "vips.version"
local log = require "vips.log"
local gvalue = require "vips.gvalue"
local vobject = require "vips.vobject"
local Image = require "vips.Image"

local band = bit.band
local band = bitops.band
local type = type
local error = error
local pairs = pairs
Expand Down
Loading