diff options
Diffstat (limited to 'util/format.lua')
-rw-r--r-- | util/format.lua | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/util/format.lua b/util/format.lua index 5f2b12be..c5e513fa 100644 --- a/util/format.lua +++ b/util/format.lua @@ -4,11 +4,10 @@ local tostring = tostring; local select = select; -local assert = assert; -local unpack = unpack; +local unpack = table.unpack or unpack; -- luacheck: ignore 113/unpack local type = type; -local function format(format, ...) +local function format(formatstring, ...) local args, args_length = { ... }, select('#', ...); -- format specifier spec: @@ -25,7 +24,7 @@ local function format(format, ...) -- process each format specifier local i = 0; - format = format:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec) + formatstring = formatstring:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec) if spec ~= "%%" then i = i + 1; local arg = args[i]; @@ -54,21 +53,12 @@ local function format(format, ...) else args[i] = tostring(arg); end - format = format .. " [%s]" + formatstring = formatstring .. " [%s]" end - return format:format(unpack(args)); -end - -local function test() - assert(format("%s", "hello") == "hello"); - assert(format("%s") == "<nil>"); - assert(format("%s", true) == "true"); - assert(format("%d", true) == "[true]"); - assert(format("%%", true) == "% [true]"); + return formatstring:format(unpack(args)); end return { format = format; - test = test; }; |