google / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Apache License 2.0
7.24k stars 1.09k forks source link

Lua Script is not compatible with LUA5.4 #101

Open dquitmann-op opened 3 years ago

dquitmann-op commented 3 years ago

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.

dquitmann-op commented 3 years ago

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

BlueFinBima commented 2 years ago

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
dmsnell commented 2 years ago

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.

dbolli commented 7 months ago

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.