forked from izaya/OC-PsychOS2
standalone executable support. again.
This commit is contained in:
parent
a533748d55
commit
2df878f3e8
@ -21,24 +21,29 @@ end
|
|||||||
function shell.interactive()
|
function shell.interactive()
|
||||||
local shenv = setmetatable({}, {__index=shindex})
|
local shenv = setmetatable({}, {__index=shindex})
|
||||||
local run = true
|
local run = true
|
||||||
|
os.setenv("PATH",{"/boot/exec","/pkg/exec"})
|
||||||
function shenv.quit()
|
function shenv.quit()
|
||||||
run = false
|
run = false
|
||||||
end
|
end
|
||||||
while run do
|
while run do
|
||||||
io.write(string.format("\27[32m%s:%s>\27[0m ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
io.write(string.format("\27[32m%s:%s>\27[0m ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
||||||
local input = io.read()
|
local w,input = pcall(io.read)
|
||||||
if input:sub(1,1) == "=" then
|
if not w then
|
||||||
input = "return "..input:sub(2)
|
print("\27[31m^C")
|
||||||
end
|
|
||||||
local f, r = load(input, "shell", "t", shenv)
|
|
||||||
if not f then
|
|
||||||
print("\27[31m"..r)
|
|
||||||
else
|
else
|
||||||
local rt = {pcall(f)}
|
if input:sub(1,1) == "=" then
|
||||||
local rs = table.remove(rt,1)
|
input = "return "..input:sub(2)
|
||||||
if not rs then io.write("\27[31m") end
|
end
|
||||||
for k,v in pairs(rt) do
|
local f, r = load(input, "shell", "t", shenv)
|
||||||
print(formatValue(v))
|
if not f then
|
||||||
|
print("\27[31m"..r)
|
||||||
|
else
|
||||||
|
local rt = {pcall(f)}
|
||||||
|
local rs = table.remove(rt,1)
|
||||||
|
if not rs then io.write("\27[31m") end
|
||||||
|
for k,v in pairs(rt) do
|
||||||
|
print(formatValue(v))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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())))
|
print(string.format("%5s %5s %5s",wrapUnits(computer.totalMemory()),wrapUnits(computer.totalMemory()-computer.freeMemory()),wrapUnits(computer.freeMemory())))
|
||||||
end
|
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.cd = os.chdir
|
||||||
shutil.mkdir = fs.makeDirectory
|
shutil.mkdir = fs.makeDirectory
|
||||||
shutil.cp = fs.copy
|
shutil.cp = fs.copy
|
||||||
shutil.rm = fs.remove
|
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})
|
||||||
|
Loading…
Reference in New Issue
Block a user