From cc7df2a95d6696a85a312310d7955f7d9270f47e Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 18 Sep 2017 07:51:48 +1000 Subject: [PATCH] added less severe failure conditions to shutil, luash should crash less now. --- modules/lib/shutil.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/lib/shutil.lua b/modules/lib/shutil.lua index c32e936..9b81b4a 100644 --- a/modules/lib/shutil.lua +++ b/modules/lib/shutil.lua @@ -10,17 +10,22 @@ function shutil.genenv() end function loadfile(fn) local f=io.open(fn,"rb") + if not f then return false, "cannot read file" end local S=f:read("*a") f:close() return load(S,"=("..fn..")","bt",os.genenv()) end function run(fn,...) - local r = {pcall(loadfile(fn),...)} + local lf = loadfile(fn) + if not lf then return false, "cannot load file" end + local r = {pcall(lf,...)} if r[1] == true then table.remove(r,1) end print(table.unpack(r)) end function srun(fn,...) - spawn(fn,print(pcall(loadfile(fn),...))) + local lf = loadfile(fn) + if not lf then return false, "cannot load file" end + spawn(fn,print(pcall(lf,...))) end