|
|
@@ -119,9 +119,49 @@ function shutil.free() -- Displays used and free memory. |
|
|
|
print(string.format("%5s %5s %5s",wrapUnits(computer.totalMemory()),wrapUnits(computer.totalMemory()-computer.freeMemory()),wrapUnits(computer.freeMemory()))) |
|
|
|
end |
|
|
|
|
|
|
|
local function pread(self,len) |
|
|
|
syslog(tostring(self)) |
|
|
|
syslog(tostring(len)) |
|
|
|
io.input(self.input) |
|
|
|
local b = io.read(len) |
|
|
|
io.input(self) |
|
|
|
if b:match("\3") then |
|
|
|
error("terminated") |
|
|
|
end |
|
|
|
return b |
|
|
|
end |
|
|
|
|
|
|
|
function shutil.which(name) |
|
|
|
local fpath |
|
|
|
for _,dir in ipairs(os.getenv("PATH")) do |
|
|
|
fpath = fpath or fs.exists(string.format("%s/%s.lua",dir,name)) and string.format("%s/%s.lua",dir,name) or fs.exists(string.format("%s/%s",dir,name)) and string.format("%s/%s",dir,name) |
|
|
|
end |
|
|
|
return fpath |
|
|
|
end |
|
|
|
|
|
|
|
shutil.cd = os.chdir |
|
|
|
shutil.mkdir = fs.makeDirectory |
|
|
|
shutil.cp = fs.copy |
|
|
|
shutil.rm = fs.remove |
|
|
|
|
|
|
|
return shutil |
|
|
|
return setmetatable({}, {__index = function(t,k) |
|
|
|
if shutil[k] then |
|
|
|
return shutil[k] |
|
|
|
end |
|
|
|
local path = shutil.which(k) |
|
|
|
if path then |
|
|
|
local fn, e = loadfile(path) |
|
|
|
if not fn then error(string.format("\n - %s",e)) end |
|
|
|
return function() |
|
|
|
local pid = os.spawn(fn,path) |
|
|
|
local ret = {require("event").pull("process_finished",pid)} |
|
|
|
if not ret[3] then |
|
|
|
error(string.format("\n - %s",ret[4])) |
|
|
|
end |
|
|
|
for i = 1, 3 do |
|
|
|
table.remove(ret,1) |
|
|
|
end |
|
|
|
return table.unpack(ret) |
|
|
|
end |
|
|
|
end |
|
|
|
end}) |