From 49a9a1e76a34d67cfa2be24cbb2e2a9db545f969 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Jul 2022 17:31:14 +0200 Subject: util: Remove various Lua 5.1 compatibility hacks Part of #1600 --- util/format.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index d709aada..611068d7 100644 --- a/util/format.lua +++ b/util/format.lua @@ -35,7 +35,6 @@ local control_symbols = { ["\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 @@ local function format(formatstring, ...) 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 -- cgit v1.2.3 From 5251c9b686fc7885c1213cc2580d66ebda2dda9b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 Jul 2022 19:07:38 +0200 Subject: compat: Remove handling of Lua 5.1 location of 'unpack' function --- util/format.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index 611068d7..35694271 100644 --- a/util/format.lua +++ b/util/format.lua @@ -6,7 +6,7 @@ -- Provides some protection from e.g. CAPEC-135, CWE-117, CWE-134, CWE-93 local tostring = tostring; -local unpack = table.unpack or unpack; -- luacheck: ignore 113/unpack +local unpack = table.unpack; local pack = require "util.table".pack; -- TODO table.pack in 5.2+ local valid_utf8 = require "util.encodings".utf8.valid; local type = type; -- cgit v1.2.3 From f8e73eba98a73e5d3dd14f73d7ce66e5503efbb4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 Jul 2022 19:15:24 +0200 Subject: compat: Use table.pack (there since Lua 5.2) over our util.table Added in d278a770eddc avoid having to deal with its absence in Lua 5.1. No longer needed when Lua 5.1 support is dropped. --- util/format.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index 35694271..203bdeab 100644 --- a/util/format.lua +++ b/util/format.lua @@ -7,7 +7,7 @@ local tostring = tostring; local unpack = table.unpack; -local pack = require "util.table".pack; -- TODO table.pack in 5.2+ +local pack = table.pack; local valid_utf8 = require "util.encodings".utf8.valid; local type = type; local dump = require "util.serialization".new("debug"); -- cgit v1.2.3 From e64c5e30c2ab1f59c5051f2bd66f053d34a6eb25 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 19 Oct 2022 16:25:05 +0200 Subject: util.startup: Provide a common Lua 5.3+ math.type() for Lua 5.2 Code deduplication --- util/format.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index 203bdeab..0631f423 100644 --- a/util/format.lua +++ b/util/format.lua @@ -11,9 +11,7 @@ local pack = table.pack; local valid_utf8 = require "util.encodings".utf8.valid; local type = type; local dump = require "util.serialization".new("debug"); -local num_type = math.type or function (n) - return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; -end +local num_type = math.type; -- In Lua 5.3+ these formats throw an error if given a float local expects_integer = { c = true, d = true, i = true, o = true, u = true, X = true, x = true, }; -- cgit v1.2.3