OC-PsychOS/exec/luash.lua

50 lines
1.2 KiB
Lua
Raw Normal View History

2017-09-13 12:52:03 +10:00
local tA = {...}
local si = tA[1]
2017-07-30 19:12:10 +10:00
spawn("lua shell",function()
os.setenv("sI",si)
2017-09-13 13:36:56 +10:00
_ENV = shutil.genenv()
coroutine.yield()
log(pcall(login))
2017-09-05 19:42:56 +10:00
print(_VERSION)
2017-07-30 19:12:10 +10:00
while true do
2017-07-31 12:10:45 +10:00
write((os.getenv("PWD") or "").."> ")
2017-08-01 16:38:43 +10:00
local inp=readln()
2017-09-05 19:08:24 +10:00
if not inp then break end
2017-08-04 17:44:37 +10:00
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))}
2017-08-04 17:44:37 +10:00
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
end
2017-07-30 19:12:10 +10:00
end
end)