Software / code / prosody
Comparison
util/bit53.lua @ 12365:af02b033bd7f
util.bit53: Support for more than 2 arguments, for compat with bit32
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 04 Mar 2022 19:37:59 +0000 |
| parent | 12358:d77d8fba44ad |
| child | 13449:9912baa541c0 |
comparison
equal
deleted
inserted
replaced
| 12364:261ce358e436 | 12365:af02b033bd7f |
|---|---|
| 1 -- Only the operators needed by net.websocket.frames are provided at this point | 1 -- Only the operators needed by net.websocket.frames are provided at this point |
| 2 return { | 2 return { |
| 3 band = function (a, b) return a & b end; | 3 band = function (a, b, ...) |
| 4 bor = function (a, b) return a | b end; | 4 local ret = a & b; |
| 5 bxor = function (a, b) return a ~ b end; | 5 if ... then |
| 6 for i = 1, select("#", ...) do | |
| 7 ret = ret & (select(i, ...)); | |
| 8 end | |
| 9 end | |
| 10 return ret; | |
| 11 end; | |
| 12 bor = function (a, b, ...) | |
| 13 local ret = a | b; | |
| 14 if ... then | |
| 15 for i = 1, select("#", ...) do | |
| 16 ret = ret | (select(i, ...)); | |
| 17 end | |
| 18 end | |
| 19 return ret; | |
| 20 end; | |
| 21 bxor = function (a, b, ...) | |
| 22 local ret = a ~ b; | |
| 23 if ... then | |
| 24 for i = 1, select("#", ...) do | |
| 25 ret = ret ~ (select(i, ...)); | |
| 26 end | |
| 27 end | |
| 28 return ret; | |
| 29 end; | |
| 6 rshift = function (a, n) return a >> n end; | 30 rshift = function (a, n) return a >> n end; |
| 7 lshift = function (a, n) return a << n end; | 31 lshift = function (a, n) return a << n end; |
| 8 }; | 32 }; |
| 9 | 33 |