2019-11-26 02:47:20 -05:00
|
|
|
local serial = require "serialization"
|
2019-07-14 06:52:56 -04:00
|
|
|
print(pcall(function()
|
2018-11-02 12:05:41 -04:00
|
|
|
local shenv = {}
|
2019-01-09 00:23:30 -05:00
|
|
|
function shenv.quit()
|
|
|
|
os.setenv("run",nil)
|
|
|
|
end
|
2019-11-05 22:28:40 -05:00
|
|
|
shenv.cd = os.chdir
|
2019-11-08 21:17:21 -05:00
|
|
|
shenv.mkdir = fs.makeDirectory
|
2019-11-19 05:46:51 -05: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-27 22:45:38 -04:00
|
|
|
setmetatable(shenv,{__index=function(_,k)
|
2019-11-19 05:46:51 -05:00
|
|
|
local fp = findPath(k)
|
2019-07-27 22:45:38 -04:00
|
|
|
if _G[k] then
|
|
|
|
return _G[k]
|
2019-11-19 05:46:51 -05:00
|
|
|
elseif fp then
|
2019-07-28 05:46:43 -04:00
|
|
|
local rqid = string.format("shell-%d",math.random(1,99999))
|
2019-07-27 22:45:38 -04:00
|
|
|
return function(...)
|
|
|
|
local tA = {...}
|
2019-11-19 05:46:51 -05:00
|
|
|
local pid = os.spawn(function() computer.pushSignal(rqid,pcall(loadfile(fp),table.unpack(tA))) end,fp)
|
2019-07-28 05:46:43 -04:00
|
|
|
local tE = {}
|
2019-07-27 22:45:38 -04:00
|
|
|
repeat
|
2019-07-28 05:46:43 -04:00
|
|
|
tE = {coroutine.yield()}
|
|
|
|
if tE[1] == rqid then
|
|
|
|
table.remove(tE,1)
|
2019-07-28 05:52:32 -04:00
|
|
|
if tE[1] == true then
|
|
|
|
table.remove(tE,1)
|
|
|
|
end
|
2019-07-28 05:46:43 -04:00
|
|
|
return table.unpack(tE)
|
|
|
|
end
|
2019-11-19 05:46:51 -05:00
|
|
|
until not os.taskInfo(pid)
|
2019-07-27 22:45:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end})
|
2019-01-08 02:03:51 -05:00
|
|
|
print(_VERSION)
|
2019-01-09 00:23:30 -05:00
|
|
|
os.setenv("run",true)
|
|
|
|
while os.getenv("run") do
|
2019-11-19 05:46:51 -05: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 02:03:51 -05:00
|
|
|
if tResult[1] == true then table.remove(tResult,1) end
|
2018-11-02 12:05:41 -04:00
|
|
|
for k,v in pairs(tResult) do
|
2019-11-26 02:47:20 -05:00
|
|
|
if type(v) == "table" then
|
|
|
|
print(serial.serialize(v))
|
|
|
|
else
|
|
|
|
print(v)
|
|
|
|
end
|
2018-11-02 12:05:41 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-14 06:52:56 -04:00
|
|
|
end))
|