made luash nicer to use
This commit is contained in:
parent
e341ada43e
commit
219d3a8326
@ -5,10 +5,41 @@ spawn("lua shell",function()
|
|||||||
while true do
|
while true do
|
||||||
write((os.getenv("PWD") or "").."> ")
|
write((os.getenv("PWD") or "").."> ")
|
||||||
local inp=readln()
|
local inp=readln()
|
||||||
if inp:sub(1,1) == "=" then inp="return "..inp:sub(2) end
|
if inp:sub(1,1) == "!" then
|
||||||
local r={pcall(load(inp))}
|
local pth = os.getenv("PATH") or "."
|
||||||
if r[1] == true then table.remove(r,1) end
|
local s,ptt = inp:sub(2), {}
|
||||||
print(table.unpack(r))
|
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
|
||||||
end
|
end
|
||||||
end,si)
|
end,si)
|
||||||
end
|
end
|
||||||
|
@ -20,9 +20,9 @@ do -- so local works
|
|||||||
tT[nP].n = n
|
tT[nP].n = n
|
||||||
tT[nP].p = cT or -1
|
tT[nP].p = cT or -1
|
||||||
if tT[cT] then
|
if tT[cT] then
|
||||||
tT[nP].u,tT[nP].ep,tT[nP].e = tT[cT].u,tT[cT].ep,e or tT[cT].e or {}
|
tT[nP].u,tT[nP].ep,tT[nP].e = tT[cT].u,tT[cT].ep,e or tT[cT].e or {["PWD"]="/boot",["PATH"]="/boot/exec:."}
|
||||||
else
|
else
|
||||||
tT[nP].u,tT[nP].ep,tT[nP].e = "superuser",1,{}
|
tT[nP].u,tT[nP].ep,tT[nP].e = "superuser",1,{["PWD"]="/boot",["PATH"]="/boot/exec:."}
|
||||||
end
|
end
|
||||||
nP = nP + 1
|
nP = nP + 1
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,11 @@ function loadfile(fn)
|
|||||||
return load(S)
|
return load(S)
|
||||||
end
|
end
|
||||||
function run(fn,...)
|
function run(fn,...)
|
||||||
print(pcall(loadfile(fn),...))
|
local r = {pcall(loadfile(fn),...)}
|
||||||
|
if r[1] == true then
|
||||||
|
table.remove(r,1)
|
||||||
|
end
|
||||||
|
print(table.unpack(r))
|
||||||
end
|
end
|
||||||
function srun(fn,...)
|
function srun(fn,...)
|
||||||
spawn(fn,print(pcall(loadfile(fn),...)))
|
spawn(fn,print(pcall(loadfile(fn),...)))
|
||||||
|
Loading…
Reference in New Issue
Block a user