Software / code / prosody
Diff
util/format.lua @ 10035:386f085820e6
util.format: Handle integer formats the same way on Lua versions without integer support
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 30 May 2019 13:54:11 +0200 |
| parent | 10034:4fca92d60040 |
| child | 11638:5f4a657136bc |
line wrap: on
line diff
--- a/util/format.lua Thu May 30 13:41:05 2019 +0200 +++ b/util/format.lua Thu May 30 13:54:11 2019 +0200 @@ -7,9 +7,12 @@ local pack = require "util.table".pack; -- TODO table.pack in 5.2+ local type = type; local dump = require "util.serialization".new("debug"); -local num_type = math.type; +local num_type = math.type or function (n) + return n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; +end -local expects_integer = num_type and { c = true, d = true, i = true, o = true, u = true, X = true, x = true, } or {}; +-- 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, }; local function format(formatstring, ...) local args = pack(...);