OC-PsychOS/exec/luash.lua

49 lines
1.2 KiB
Lua

local tA = {...}
local si = tA[1]
spawn("lua shell",function()
_ENV = shutil.genenv()
coroutine.yield()
log(pcall(login))
print(_VERSION)
while true do
write((os.getenv("PWD") or "").."> ")
local inp=readln()
if not inp then break end
if inp:sub(1,1) == "!" then
local pth = os.getenv("PATH") or "."
local s,ptt = inp:sub(2), {}
for w in s:gmatch("%S+") do table.insert(ptt,w) end
local prg = table.remove(ptt,1)
for d in pth:gmatch("[^:]+") do
_,lex = pcall(fs.exists,d.."/"..prg..".lua")
_,nex = pcall(fs.exists,d.."/"..prg)
if lex then
run(d.."/"..prg..".lua",table.unpack(ptt))
break
elseif nex then
run(d.."/"..prg,table.unpack(ptt))
break
end
end
elseif inp:sub(1,1) == "$" then
local s,ptt = inp:sub(2), {}
for w in s:gmatch("%S+") do table.insert(ptt,w) end
local prg = table.remove(ptt,1)
local r={pcall(_ENV[prg],table.unpack(ptt))}
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
else
if inp:sub(1,1) == "=" then
inp="return "..inp:sub(2)
end
local r={pcall(load(inp,"shell","bt",_ENV))}
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
end
end
end,{sI=si})