made lush prefer functions/builtins rather than files where possible

This commit is contained in:
Izaya 2017-10-07 23:34:18 +11:00
parent 0bb3921781
commit 3a3e83691a
1 changed files with 8 additions and 8 deletions

View File

@ -10,6 +10,14 @@ spawn("lua shell", function() print(pcall(function()
local function shexec(line)
local words = {}
for w in line:gmatch("%S+") do table.insert(words,w) end
if _ENV[words[1]] then
local prg = table.remove(words,1)
local r={pcall(_ENV[prg],table.unpack(words))}
if r[1] == true then
table.remove(r,1)
end
return table.unpack(r)
end
local pth = os.getenv("PATH") or "."
for d in pth:gmatch("[^:]+") do
local prg = words[1]
@ -24,14 +32,6 @@ spawn("lua shell", function() print(pcall(function()
return pcall(loadfile(d.."/"..prg,table.unpack(words)))
end
end
if _ENV[words[1]] then
local prg = table.remove(words,1)
local r={pcall(_ENV[prg],table.unpack(words))}
if r[1] == true then
table.remove(r,1)
end
return table.unpack(r)
end
if line:sub(1,1) == "=" then
line="return "..line:sub(2)
end