Mercurial > prosody-hg
comparison util/format.lua @ 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 | f7946c8e502f |
| children | 39ae08180c81 |
comparison
equal
deleted
inserted
replaced
| 12572:35a9ed6b7896 | 12573:0f4feaf9ca64 |
|---|---|
| 33 ["\024"] = "\226\144\152", ["\025"] = "\226\144\153", ["\026"] = "\226\144\154", | 33 ["\024"] = "\226\144\152", ["\025"] = "\226\144\153", ["\026"] = "\226\144\154", |
| 34 ["\027"] = "\226\144\155", ["\028"] = "\226\144\156", ["\029"] = "\226\144\157", | 34 ["\027"] = "\226\144\155", ["\028"] = "\226\144\156", ["\029"] = "\226\144\157", |
| 35 ["\030"] = "\226\144\158", ["\031"] = "\226\144\159", ["\127"] = "\226\144\161", | 35 ["\030"] = "\226\144\158", ["\031"] = "\226\144\159", ["\127"] = "\226\144\161", |
| 36 }; | 36 }; |
| 37 local supports_p = pcall(string.format, "%p", ""); -- >= Lua 5.4 | 37 local supports_p = pcall(string.format, "%p", ""); -- >= Lua 5.4 |
| 38 local supports_a = pcall(string.format, "%a", 0.0); -- > Lua 5.1 | |
| 39 | 38 |
| 40 local function format(formatstring, ...) | 39 local function format(formatstring, ...) |
| 41 local args = pack(...); | 40 local args = pack(...); |
| 42 local args_length = args.n; | 41 local args_length = args.n; |
| 43 | 42 |
| 91 args[i] = tostring(arg); | 90 args[i] = tostring(arg); |
| 92 return "[%s]"; | 91 return "[%s]"; |
| 93 elseif expects_positive[option] and arg < 0 then | 92 elseif expects_positive[option] and arg < 0 then |
| 94 args[i] = tostring(arg); | 93 args[i] = tostring(arg); |
| 95 return "[%s]"; | 94 return "[%s]"; |
| 96 elseif (option == "a" or option == "A") and not supports_a then | |
| 97 return "%x"; | |
| 98 else | 95 else |
| 99 return -- acceptable number | 96 return -- acceptable number |
| 100 end | 97 end |
| 101 end | 98 end |
| 102 | 99 |
