added less severe failure conditions to shutil, luash should crash less now.

This commit is contained in:
Izaya 2017-09-18 07:51:48 +10:00
parent 50d77f2904
commit 3cf9a5e42a
1 changed files with 7 additions and 2 deletions

View File

@ -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