2019-11-26 18:47:20 +11:00
|
|
|
local serial = require "serialization"
|
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-11-06 14:28:40 +11:00
|
|
|
shenv.cd = os.chdir
|
2019-11-09 13:17:21 +11:00
|
|
|
shenv.mkdir = fs.makeDirectory
|
2019-11-19 21:46:51 +11:00
|
|
|
local function findPath(name)
|
|
|
|
path = os.getenv("PATH") or "/boot/exec"
|
|
|
|
for l in path:gmatch("[^\n]+") do
|
|
|
|
if fs.exists(l.."/"..name) then
|
|
|
|
return l.."/"..name
|
|
|
|
elseif fs.exists(l.."/"..name..".lua") then
|
|
|
|
return l.."/"..name..".lua"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-28 12:45:38 +10:00
|
|
|
setmetatable(shenv,{__index=function(_,k)
|
2019-11-19 21:46:51 +11:00
|
|
|
local fp = findPath(k)
|
2019-07-28 12:45:38 +10:00
|
|
|
if _G[k] then
|
|
|
|
return _G[k]
|
2019-11-19 21:46:51 +11:00
|
|
|
elseif fp 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-11-19 21:46:51 +11:00
|
|
|
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
2019-07-28 19:46:43 +10:00
|
|
|
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-11-19 21:46:51 +11:00
|
|
|
until not os.taskInfo(pid)
|
2019-07-28 12:45:38 +10:00
|
|
|
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-11-19 21:46:51 +11:00
|
|
|
io.write(string.format("%s:%s> ",os.getenv("HOSTNAME") or "localhost",(os.getenv("PWD") or _VERSION)))
|
|
|
|
local input=io.read()
|
|
|
|
if input:sub(1,1) == "=" then
|
|
|
|
input = "return "..input:sub(2)
|
|
|
|
end
|
|
|
|
tResult = {pcall(load(input,"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
|
2019-11-26 18:47:20 +11:00
|
|
|
if type(v) == "table" then
|
|
|
|
print(serial.serialize(v))
|
|
|
|
else
|
|
|
|
print(v)
|
|
|
|
end
|
2018-11-03 03:05:41 +11:00
|
|
|
end
|
|
|
|
end
|
2019-07-14 20:52:56 +10:00
|
|
|
end))
|