Migrate to Lua 5.4

This commit is contained in:
Jan200101
2021-12-31 13:53:01 +01:00
parent 416a06c566
commit 99ddf1fb92
12 changed files with 98 additions and 56 deletions
+30
View File
@@ -0,0 +1,30 @@
local bit = {}
local LUA_NBITS = 32
local ALLONES = (~(((~0) << (LUA_NBITS - 1)) << 1))
local function trim(x)
return (x & ALLONES)
end
local function mask(n)
return (~((ALLONES << 1) << ((n) - 1)))
end
function bit.extract(n, field, width)
local r = trim(field)
local f = width
r = (r >> f) & mask(width)
return r
end
function bit.replace(n, v, field, width)
local r = trim(v);
local v = trim(field);
local f = width
local m = mask(width);
r = (r & ~(m << f)) | ((v & m) << f);
return r
end
return bit