diff options
author | Kim Alvefur <zash@zash.se> | 2021-12-11 20:40:23 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-12-11 20:40:23 +0100 |
commit | db41cd8e4df7bb1003e9dfb60671ef56113ad69c (patch) | |
tree | ff5b8f1a4ac0cd81b9b200f2d496f976e107da66 /util | |
parent | 3d0844a4f5dbc7f8eb71d888c9b117e68de0825c (diff) | |
download | prosody-db41cd8e4df7bb1003e9dfb60671ef56113ad69c.tar.gz prosody-db41cd8e4df7bb1003e9dfb60671ef56113ad69c.zip |
util.format: Fix Lua 5.1 quirks thanks to ALL THE TESTS
Diffstat (limited to 'util')
-rw-r--r-- | util/format.lua | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/util/format.lua b/util/format.lua index da48c60a..76296fbf 100644 --- a/util/format.lua +++ b/util/format.lua @@ -29,7 +29,8 @@ local control_symbols = { ["\027"] = "\226\144\155", ["\028"] = "\226\144\156", ["\029"] = "\226\144\157", ["\030"] = "\226\144\158", ["\031"] = "\226\144\159", ["\127"] = "\226\144\161", }; -local supports_p = pcall(string.format, "%p", ""); +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(...); @@ -66,6 +67,8 @@ local function format(formatstring, ...) if option == "s" and t == "string" and not arg:find("[%z\1-\31\128-\255]") then -- No UTF-8 or control characters, assumed to be the common case. return + elseif option == "s" and t ~= "string" then + args[i] = tostring(arg); end if option ~= "s" and option ~= "q" and option ~= "p" then @@ -79,6 +82,8 @@ local function format(formatstring, ...) elseif expects_integer[option] and num_type(arg) ~= "integer" 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 |