From 236abc4afed5321e0da406e369a8b23dac6fef83 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 May 2019 13:41:05 +0200 Subject: util.format: Handle formats expecting an integer in Lua 5.3+ (fixes #1371) --- util/format.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index c31f599f..857bb694 100644 --- a/util/format.lua +++ b/util/format.lua @@ -7,6 +7,9 @@ local unpack = table.unpack or unpack; -- luacheck: ignore 113/unpack 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 expects_integer = num_type and { c = true, d = true, i = true, o = true, u = true, X = true, x = true, } or {}; local function format(formatstring, ...) local args = pack(...); @@ -43,6 +46,9 @@ local function format(formatstring, ...) elseif type(arg) ~= "number" then -- arg isn't number as expected? args[i] = tostring(arg); spec = "[%s]"; + elseif expects_integer[option] and num_type(arg) ~= "integer" then + args[i] = tostring(arg); + spec = "[%s]"; end end return spec; -- cgit v1.2.3