diff-match-patch
diff-match-patch copied to clipboard
Lua Script is not compatible with LUA5.4
In https://github.com/google/diff-match-patch/blob/62f2e689f498f9c92dbc588c58750addec9b1654/lua/diff_match_patch.lua#L30-L31 the functions band
, bor
, and lshift
are imported from bit32
. The above comment (https://github.com/google/diff-match-patch/blob/62f2e689f498f9c92dbc588c58750addec9b1654/lua/diff_match_patch.lua#L22-L28) says, for Lua 5.1 and earlier one has to install the BitOp Library.
When trying to use this awesome script in Lua5.4 I realized, the bit32
is no longer included (I'm not sure about Lua5.3, but I could not find bit32
in the user manual https://www.lua.org/manual/5.3/manual.html).
I solved the issue by including custom implementations from https://github.com/Egor-Skriptunoff/pure_lua_SHA/blob/master/sha2.lua, but maybe it would be good to include something like this into the script or at least update the comment above to make clear, it is only working with Lua5.2 and not with later versions.
If I can help in any way by contributing a pull request, let me know.
I just realized, Lua5.3+ seems to support bit-wise operations native: http://lua-users.org/wiki/BitwiseOperators and https://www.lua.org/manual/5.4/manual.html#3.4.2
While not Lua release agnostic, I got his running with Lua 5.4 by deleting the local bit32 definitions
--local band, bor, lshift
-- = bit32.band, bit32.bor, bit32.lshift
and then added then adding them as local functions
local function band(a,b)
return(a&b)
end
local function bor(a,b)
return(a|b)
end
local function lshift(a,b)
return(a<<b)
end
A pull request would be helpful! Looks like it's a small issue, and if that works I can't see it causing much harm as long as the tests continue to pass for Lua.
FYI, I'm running lua 5.4.6 on macOS 14.1.1 and I needed to install bit32 via luarocks
$ luarocks install bit32
then I added
bit32 = require( "bit32" )
to lua scripts as required.
Regards, Derek.