2019-07-14 20:52:56 +10:00
|
|
|
print(pcall(function()
|
2018-11-03 03:05:41 +11:00
|
|
|
local shenv = {}
|
2019-01-09 16:23:30 +11:00
|
|
|
function shenv.quit()
|
|
|
|
os.setenv("run",nil)
|
|
|
|
end
|
2019-07-28 13:03:04 +10:00
|
|
|
function shenv.cd(p)
|
|
|
|
if p:sub(1,1) == "/" then
|
|
|
|
if fs.list(p) then
|
|
|
|
os.setenv("PWD",p)
|
|
|
|
else
|
|
|
|
print("no such directory: "..p)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local np = {}
|
|
|
|
for k,v in pairs(fs.segments(os.getenv("PWD").."/"..p)) do
|
|
|
|
if v == ".." then
|
|
|
|
np[#np] = nil
|
|
|
|
else
|
|
|
|
np[#np+1] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
os.setenv("PWD","/"..table.concat(np,"/"))
|
|
|
|
end
|
|
|
|
end
|
2019-07-28 12:45:38 +10:00
|
|
|
setmetatable(shenv,{__index=function(_,k)
|
|
|
|
if _G[k] then
|
|
|
|
return _G[k]
|
|
|
|
elseif fs.exists("/boot/exec/"..k..".lua") then
|
2019-07-28 19:46:43 +10:00
|
|
|
local rqid = string.format("shell-%d",math.random(1,99999))
|
2019-07-28 12:45:38 +10:00
|
|
|
return function(...)
|
|
|
|
local tA = {...}
|
2019-07-28 19:46:43 +10:00
|
|
|
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile("/boot/exec/"..k..".lua"),table.unpack(tA))) end,"/boot/exec/"..k..".lua")
|
|
|
|
local tE = {}
|
2019-07-28 12:45:38 +10:00
|
|
|
repeat
|
2019-07-28 19:46:43 +10:00
|
|
|
tE = {coroutine.yield()}
|
|
|
|
if tE[1] == rqid then
|
|
|
|
table.remove(tE,1)
|
2019-07-28 19:52:32 +10:00
|
|
|
if tE[1] == true then
|
|
|
|
table.remove(tE,1)
|
|
|
|
end
|
2019-07-28 19:46:43 +10:00
|
|
|
return table.unpack(tE)
|
|
|
|
end
|
2019-07-28 12:45:38 +10:00
|
|
|
until tTasks[pid] == nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end})
|
2019-01-08 18:03:51 +11:00
|
|
|
print(_VERSION)
|
2019-01-09 16:23:30 +11:00
|
|
|
os.setenv("run",true)
|
|
|
|
while os.getenv("run") do
|
2019-01-08 18:03:51 +11:00
|
|
|
io.write((os.getenv("PWD") or _VERSION).."> ")
|
2018-11-03 03:05:41 +11:00
|
|
|
tResult = {pcall(load(io.read(),"shell","t",shenv))}
|
2019-01-08 18:03:51 +11:00
|
|
|
if tResult[1] == true then table.remove(tResult,1) end
|
2018-11-03 03:05:41 +11:00
|
|
|
for k,v in pairs(tResult) do
|
|
|
|
print(v)
|
|
|
|
end
|
|
|
|
end
|
2019-07-14 20:52:56 +10:00
|
|
|
end))
|