From d007771f8da390816640fa3839b29dcbaa5862d2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 28 Nov 2018 20:36:53 +0100 Subject: util.format: Tweak how nil values are handled Because [] seems exsessive --- util/format.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'util/format.lua') diff --git a/util/format.lua b/util/format.lua index c5e513fa..16c57bc6 100644 --- a/util/format.lua +++ b/util/format.lua @@ -28,13 +28,12 @@ local function format(formatstring, ...) if spec ~= "%%" then i = i + 1; local arg = args[i]; - if arg == nil then -- special handling for nil - arg = "" - args[i] = ""; - end local option = spec:sub(-1); - if option == "q" or option == "s" then -- arg should be string + if arg == nil then + args[i] = "nil"; + spec = "<%s>"; + elseif option == "q" or option == "s" then -- arg should be string args[i] = tostring(arg); elseif type(arg) ~= "number" then -- arg isn't number as expected? args[i] = tostring(arg); -- cgit v1.2.3