OC-PsychOS/modules/applications/luash.lua

47 lines
1.2 KiB
Lua
Raw Normal View History

2017-07-30 19:12:10 +10:00
function luash(si)
spawn("lua shell",function()
print(_OSVERSION..", "..string.format("%4d",computer.totalMemory()/1024).."K memory")
2017-09-05 19:08:24 +10:00
print(MOTD,net.id,_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))}
if r[1] == true then
table.remove(r,1)
end
print(table.unpack(r))
end
2017-07-30 19:12:10 +10:00
end
2017-09-01 09:07:07 +10:00
end,{sI=si})
2017-07-30 19:12:10 +10:00
end