util/bit53.lua
author Kim Alvefur <zash@zash.se>
Sun, 24 Mar 2024 20:39:42 +0100
changeset 13466 720aed1f5cf2
parent 13453 9912baa541c0
permissions -rw-r--r--
util.startup: Check root after detecting platform and reading config (thanks SigmaTel71) Ensures that startup.detect_platform() runs so know whether to use the POSIX method of checking the current user or something else. Also after reading the config so we know whether the root override setting is set.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10245
48f7cda4174d util.bitops: Library to find appropriate bitwise library (closes #1395)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     1
-- Only the operators needed by net.websocket.frames are provided at this point
48f7cda4174d util.bitops: Library to find appropriate bitwise library (closes #1395)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     2
return {
12369
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     3
	band   = function (a, b, ...)
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     4
		local ret = a & b;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     5
		if ... then
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     6
			for i = 1, select("#", ...) do
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     7
				ret = ret & (select(i, ...));
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     8
			end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
     9
		end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    10
		return ret;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    11
	end;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    12
	bor    = function (a, b, ...)
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    13
		local ret = a | b;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    14
		if ... then
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    15
			for i = 1, select("#", ...) do
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    16
				ret = ret | (select(i, ...));
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    17
			end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    18
		end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    19
		return ret;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    20
	end;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    21
	bxor   = function (a, b, ...)
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    22
		local ret = a ~ b;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    23
		if ... then
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    24
			for i = 1, select("#", ...) do
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    25
				ret = ret ~ (select(i, ...));
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    26
			end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    27
		end
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    28
		return ret;
af02b033bd7f util.bit53: Support for more than 2 arguments, for compat with bit32
Matthew Wild <mwild1@gmail.com>
parents: 12362
diff changeset
    29
	end;
13453
9912baa541c0 util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents: 12369
diff changeset
    30
	bnot   = function (x)
9912baa541c0 util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents: 12369
diff changeset
    31
		return ~x;
9912baa541c0 util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents: 12369
diff changeset
    32
	end;
12362
d77d8fba44ad util.bit53: Add left- and right shift operations
Kim Alvefur <zash@zash.se>
parents: 10245
diff changeset
    33
	rshift = function (a, n) return a >> n end;
d77d8fba44ad util.bit53: Add left- and right shift operations
Kim Alvefur <zash@zash.se>
parents: 10245
diff changeset
    34
	lshift = function (a, n) return a << n end;
10245
48f7cda4174d util.bitops: Library to find appropriate bitwise library (closes #1395)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    35
};
48f7cda4174d util.bitops: Library to find appropriate bitwise library (closes #1395)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    36