moved the run-related functions into the fs library
This commit is contained in:
parent
0918704357
commit
237b1c5e09
@ -248,3 +248,24 @@ function fs.mv(s,d)
|
|||||||
fs.cp(s,d)
|
fs.cp(s,d)
|
||||||
fs.rm(s)
|
fs.rm(s)
|
||||||
end
|
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 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,...)
|
||||||
|
local lf = loadfile(fn)
|
||||||
|
if not lf then return false, "cannot load file" end
|
||||||
|
spawn(fn,print(pcall(lf,...)))
|
||||||
|
end
|
||||||
|
@ -8,24 +8,3 @@ function shutil.genenv()
|
|||||||
end
|
end
|
||||||
return et
|
return et
|
||||||
end
|
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 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,...)
|
|
||||||
local lf = loadfile(fn)
|
|
||||||
if not lf then return false, "cannot load file" end
|
|
||||||
spawn(fn,print(pcall(lf,...)))
|
|
||||||
end
|
|
||||||
|
Loading…
Reference in New Issue
Block a user