# HG changeset patch # User Kim Alvefur # Date 1559217251 -7200 # Node ID 386f085820e6fd1bfebccca5a2de4ff3b7f80d77 # Parent 4fca92d60040e306c0250b9ed4943fc47c1aaa7e util.format: Handle integer formats the same way on Lua versions without integer support diff -r 4fca92d60040 -r 386f085820e6 spec/util_format_spec.lua --- a/spec/util_format_spec.lua Thu May 30 13:41:05 2019 +0200 +++ b/spec/util_format_spec.lua Thu May 30 13:54:11 2019 +0200 @@ -13,6 +13,7 @@ assert.equal("% [true]", format("%%", true)); assert.equal("{ }", format("%q", { })); assert.equal("[1.5]", format("%d", 1.5)); + assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)); end); end); end); diff -r 4fca92d60040 -r 386f085820e6 util/format.lua --- 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(...);