Changeset

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
parents 12572:35a9ed6b7896
children 12574:18d33668c5fa
files util/bitcompat.lua util/format.lua util/human/io.lua util/human/units.lua util/prosodyctl/shell.lua
diffstat 5 files changed, 2 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/util/bitcompat.lua	Sat Jul 02 17:30:34 2022 +0200
+++ b/util/bitcompat.lua	Sat Jul 02 17:31:14 2022 +0200
@@ -5,12 +5,6 @@
 -- Lua 5.2 has it by default
 if _G.bit32 then
 	return _G.bit32;
-else
-	-- Lua 5.1 may have it as a standalone module that can be installed
-	local ok, bitop = pcall(require, "bit32")
-	if ok then
-		return bitop;
-	end
 end
 
 do
@@ -21,12 +15,4 @@
 	end
 end
 
-do
-	-- Lastly, try the LuaJIT bitop library
-	local ok, bitop = pcall(require, "bit")
-	if ok then
-		return bitop;
-	end
-end
-
 error "No bit module found. See https://prosody.im/doc/depends#bitop";
--- a/util/format.lua	Sat Jul 02 17:30:34 2022 +0200
+++ b/util/format.lua	Sat Jul 02 17:31:14 2022 +0200
@@ -35,7 +35,6 @@
 	["\030"] = "\226\144\158", ["\031"] = "\226\144\159", ["\127"] = "\226\144\161",
 };
 local supports_p = pcall(string.format, "%p", ""); -- >= Lua 5.4
-local supports_a = pcall(string.format, "%a", 0.0); -- > Lua 5.1
 
 local function format(formatstring, ...)
 	local args = pack(...);
@@ -93,8 +92,6 @@
 			elseif expects_positive[option] and arg < 0 then
 				args[i] = tostring(arg);
 				return "[%s]";
-			elseif (option == "a" or option == "A") and not supports_a then
-				return "%x";
 			else
 				return -- acceptable number
 			end
--- a/util/human/io.lua	Sat Jul 02 17:30:34 2022 +0200
+++ b/util/human/io.lua	Sat Jul 02 17:31:14 2022 +0200
@@ -30,10 +30,7 @@
 end
 
 local function getpass()
-	local stty_ret, _, status_code = os.execute("stty -echo 2>/dev/null");
-	if status_code then -- COMPAT w/ Lua 5.1
-		stty_ret = status_code;
-	end
+	local stty_ret = os.execute("stty -echo 2>/dev/null");
 	if stty_ret ~= 0 then
 		io.write("\027[08m"); -- ANSI 'hidden' text attribute
 	end
--- a/util/human/units.lua	Sat Jul 02 17:30:34 2022 +0200
+++ b/util/human/units.lua	Sat Jul 02 17:31:14 2022 +0200
@@ -6,14 +6,6 @@
 local math_min = math.min;
 local unpack = table.unpack or unpack; --luacheck: ignore 113
 
-if math_log(10, 10) ~= 1 then
-	-- Lua 5.1 COMPAT
-	local log10 = math.log10;
-	function math_log(n, base)
-		return log10(n) / log10(base);
-	end
-end
-
 local large = {
 	"k", 1000,
 	"M", 1000000,
--- a/util/prosodyctl/shell.lua	Sat Jul 02 17:30:34 2022 +0200
+++ b/util/prosodyctl/shell.lua	Sat Jul 02 17:31:14 2022 +0200
@@ -80,8 +80,7 @@
 	if arg[1] then
 		if arg[2] then
 			-- prosodyctl shell module reload foo bar.com --> module:reload("foo", "bar.com")
-			-- COMPAT Lua 5.1 doesn't have the separator argument to string.rep
-			arg[1] = string.format("%s:%s("..string.rep("%q, ", #arg-2):sub(1, -3)..")", unpack(arg));
+			arg[1] = string.format("%s:%s("..string.rep("%q", #arg-2,", ")..")", unpack(arg));
 		end
 
 		client.events.add_handler("connected", function()