added less severe failure conditions to shutil, luash should crash less now.
This commit is contained in:
parent
1ffec30452
commit
cc7df2a95d
@ -10,17 +10,22 @@ function shutil.genenv()
|
|||||||
end
|
end
|
||||||
function loadfile(fn)
|
function loadfile(fn)
|
||||||
local f=io.open(fn,"rb")
|
local f=io.open(fn,"rb")
|
||||||
|
if not f then return false, "cannot read file" end
|
||||||
local S=f:read("*a")
|
local S=f:read("*a")
|
||||||
f:close()
|
f:close()
|
||||||
return load(S,"=("..fn..")","bt",os.genenv())
|
return load(S,"=("..fn..")","bt",os.genenv())
|
||||||
end
|
end
|
||||||
function run(fn,...)
|
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
|
if r[1] == true then
|
||||||
table.remove(r,1)
|
table.remove(r,1)
|
||||||
end
|
end
|
||||||
print(table.unpack(r))
|
print(table.unpack(r))
|
||||||
end
|
end
|
||||||
function srun(fn,...)
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user