Software / code / prosody
Comparison
util/bitcompat.lua @ 12573:0f4feaf9ca64
util: Remove various Lua 5.1 compatibility hacks
Part of #1600
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 02 Jul 2022 17:31:14 +0200 |
| parent | 10241:48f7cda4174d |
| child | 12975:d10957394a3c |
comparison
equal
deleted
inserted
replaced
| 12572:35a9ed6b7896 | 12573:0f4feaf9ca64 |
|---|---|
| 3 -- First try the bit32 lib | 3 -- First try the bit32 lib |
| 4 -- Lua 5.3 has it with compat enabled | 4 -- Lua 5.3 has it with compat enabled |
| 5 -- Lua 5.2 has it by default | 5 -- Lua 5.2 has it by default |
| 6 if _G.bit32 then | 6 if _G.bit32 then |
| 7 return _G.bit32; | 7 return _G.bit32; |
| 8 else | |
| 9 -- Lua 5.1 may have it as a standalone module that can be installed | |
| 10 local ok, bitop = pcall(require, "bit32") | |
| 11 if ok then | |
| 12 return bitop; | |
| 13 end | |
| 14 end | 8 end |
| 15 | 9 |
| 16 do | 10 do |
| 17 -- Lua 5.3 and 5.4 would be able to use native infix operators | 11 -- Lua 5.3 and 5.4 would be able to use native infix operators |
| 18 local ok, bitop = pcall(require, "util.bit53") | 12 local ok, bitop = pcall(require, "util.bit53") |
| 19 if ok then | 13 if ok then |
| 20 return bitop; | 14 return bitop; |
| 21 end | 15 end |
| 22 end | 16 end |
| 23 | 17 |
| 24 do | |
| 25 -- Lastly, try the LuaJIT bitop library | |
| 26 local ok, bitop = pcall(require, "bit") | |
| 27 if ok then | |
| 28 return bitop; | |
| 29 end | |
| 30 end | |
| 31 | |
| 32 error "No bit module found. See https://prosody.im/doc/depends#bitop"; | 18 error "No bit module found. See https://prosody.im/doc/depends#bitop"; |