From 3c84d1fbdd5f017ddea60b5f89008843906902ea Mon Sep 17 00:00:00 2001 From: Reuh Date: Wed, 9 Jun 2021 13:43:52 +0200 Subject: [PATCH] Fix string.format errors on Lua 5.1 when using booleans or nil --- bin/can | 2 +- bin/canc | 2 +- candran.can | 4 ++-- candran.lua | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/can b/bin/can index cad0270..8c4cdc7 100644 --- a/bin/can +++ b/bin/can @@ -15,7 +15,7 @@ if args.help or args.h then print("Default options:") for opt, val in pairs(candran.default) do if type(val) == "string" then val = val:gsub("\n", "\\n") end - print((" %s=%q"):format(opt, val)) + print((" %s=%q"):format(opt, tostring(val))) end return end diff --git a/bin/canc b/bin/canc index b87cb8f..32265ef 100644 --- a/bin/canc +++ b/bin/canc @@ -23,7 +23,7 @@ if #arg < 1 or args.help or args.h then print("Default options:") for opt, val in pairs(candran.default) do if type(val) == "string" then val = val:gsub("\n", "\\n") end - print((" %s=%q"):format(opt, val)) + print((" %s=%q"):format(opt, tostring(val))) end return end diff --git a/candran.can b/candran.can index 57f115d..aa34258 100644 --- a/candran.can +++ b/candran.can @@ -203,7 +203,7 @@ local codeCache = {} function candran.loadfile(filepath, env, options) local f, err = io.open(filepath) if not f then - return nil, "cannot open %s":format(err) + return nil, "cannot open %s":format(tostring(err)) end local content = f:read("*a") f:close() @@ -321,7 +321,7 @@ function candran.searcher(modpath) if r then return r(modpath, filepath) else - error("error loading candran module '%s' from file '%s':\n\t%s":format(modpath, filepath, s), 0) + error("error loading candran module '%s' from file '%s':\n\t%s":format(modpath, filepath, tostring(s)), 0) end end, filepath end diff --git a/candran.lua b/candran.lua index 51a26ad..4512e48 100644 --- a/candran.lua +++ b/candran.lua @@ -6541,7 +6541,7 @@ local codeCache = {} -- candran.can:200 candran["loadfile"] = function(filepath, env, options) -- candran.can:203 local f, err = io["open"](filepath) -- candran.can:204 if not f then -- candran.can:205 -return nil, ("cannot open %s"):format(err) -- candran.can:206 +return nil, ("cannot open %s"):format(tostring(err)) -- candran.can:206 end -- candran.can:206 local content = f:read("*a") -- candran.can:208 f:close() -- candran.can:209 @@ -6651,7 +6651,7 @@ if r then -- candran.can:321 return r(modpath, filepath) -- candran.can:322 else -- candran.can:322 error(("error loading candran module '%s' from file '%s':\ - %s"):format(modpath, filepath, s), 0) -- candran.can:324 + %s"):format(modpath, filepath, tostring(s)), 0) -- candran.can:324 end -- candran.can:324 end, filepath -- candran.can:326 end -- candran.can:326