2019-11-26 02:47:20 -05:00
|
|
|
local serial = require "serialization"
|
2019-12-15 22:37:29 -05:00
|
|
|
local event = require "event"
|
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-27 22:45:38 -04:00
|
|
|
return function(...)
|
|
|
|
local tA = {...}
|
2019-12-15 22:37:29 -05:00
|
|
|
local pid = os.spawnfile(fp,fp,table.unpack(tA))
|
2019-12-16 00:43:32 -05:00
|
|
|
local tE = {event.pull("process_finished",pid)}
|
2019-12-15 22:37:29 -05:00
|
|
|
if tE[1] == true then
|
|
|
|
table.remove(tE,1)
|
|
|
|
end
|
|
|
|
return table.unpack(tE)
|
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
|
2019-12-15 22:37:29 -05:00
|
|
|
print(serial.serialize(v,true))
|
2019-11-26 02:47:20 -05:00
|
|
|
else
|
|
|
|
print(v)
|
|
|
|
end
|
2018-11-02 12:05:41 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-14 06:52:56 -04:00
|
|
|
end))
|