mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-13 03:43:08 +00:00
Merge pull request #298 from SquidDev-CC/ComputerCraft/feature/luaj-bit32
Replace BitAPI with a LuaJ implementation of bit32
This commit is contained in:
@@ -55,18 +55,6 @@ if _VERSION == "Lua 5.1" then
|
||||
table.unpack = unpack
|
||||
table.pack = function( ... ) return { n = select( "#", ... ), ... } end
|
||||
|
||||
-- Install the bit32 api
|
||||
local nativebit = bit
|
||||
bit32 = {}
|
||||
bit32.arshift = nativebit.brshift
|
||||
bit32.band = nativebit.band
|
||||
bit32.bnot = nativebit.bnot
|
||||
bit32.bor = nativebit.bor
|
||||
bit32.btest = function( a, b ) return nativebit.band(a,b) ~= 0 end
|
||||
bit32.bxor = nativebit.bxor
|
||||
bit32.lshift = nativebit.blshift
|
||||
bit32.rshift = nativebit.blogic_rshift
|
||||
|
||||
if _CC_DISABLE_LUA51_FEATURES then
|
||||
-- Remove the Lua 5.1 features that will be removed when we update to Lua 5.2, for compatibility testing.
|
||||
-- See "disable_lua51_functions" in ComputerCraft.cfg
|
||||
@@ -76,11 +64,21 @@ if _VERSION == "Lua 5.1" then
|
||||
unpack = nil
|
||||
math.log10 = nil
|
||||
table.maxn = nil
|
||||
bit = nil
|
||||
else
|
||||
-- Inject a stub for the old bit library
|
||||
_G.bit = {
|
||||
bnot = bit32.bnot,
|
||||
band = bit32.band,
|
||||
bor = bit32.bor,
|
||||
bxor = bit32.bxor,
|
||||
brshift = bit32.arshift,
|
||||
blshift = bit32.lshift,
|
||||
blogic_rshift = bit32.rshift
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if _VERSION == "Lua 5.3" then
|
||||
if _VERSION == "Lua 5.3" and not bit32 then
|
||||
-- If we're on Lua 5.3, install the bit32 api from Lua 5.2
|
||||
-- (Loaded from a string so this file will still parse on <5.3 lua)
|
||||
load( [[
|
||||
|
||||
Reference in New Issue
Block a user