mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
Merge branch 'master-MC1.11' into master-MC1.12
This commit is contained in:
commit
b9d4d425ea
@ -187,22 +187,21 @@ function sh.internal.glob(eword)
|
||||
end
|
||||
|
||||
function sh.getMatchingPrograms(baseName)
|
||||
if not baseName or baseName == "" then return {} end
|
||||
local result = {}
|
||||
local result_keys = {} -- cache for fast value lookup
|
||||
-- TODO only matching files with .lua extension for now, might want to
|
||||
-- extend this to other extensions at some point? env var? file attrs?
|
||||
if not baseName or #baseName == 0 then
|
||||
baseName = "^(.*)%.lua$"
|
||||
else
|
||||
baseName = "^(" .. text.escapeMagic(baseName) .. ".*)%.lua$"
|
||||
local function check(key)
|
||||
if key:find(baseName, 1, true) == 1 and not result_keys[key] then
|
||||
table.insert(result, key)
|
||||
result_keys[key] = true
|
||||
end
|
||||
end
|
||||
for alias in shell.aliases() do
|
||||
check(alias)
|
||||
end
|
||||
for basePath in string.gmatch(os.getenv("PATH"), "[^:]+") do
|
||||
for file in fs.list(shell.resolve(basePath)) do
|
||||
local match = file:match(baseName)
|
||||
if match and not result_keys[match] then
|
||||
table.insert(result, match)
|
||||
result_keys[match] = true
|
||||
end
|
||||
check(file:gsub("%.lua$", ""))
|
||||
end
|
||||
end
|
||||
return result
|
||||
|
@ -108,17 +108,17 @@ function io.write(...)
|
||||
return io.output():write(...)
|
||||
end
|
||||
|
||||
function io.dup(fd)
|
||||
return setmetatable({
|
||||
close = function(self) self._closed = true end,
|
||||
}, {__index = function(_, key)
|
||||
local fd_value = fd[key]
|
||||
local dup_mt = {__index = function(dfd, key)
|
||||
if key == "close" or dfd._closed then dfd._closed = true return end
|
||||
local fd_value = dfd.fd[key]
|
||||
if type(fd_value) ~= "function" then return fd_value end
|
||||
return function(self, ...)
|
||||
if self._closed then return nil, "closed stream" end
|
||||
return fd_value(fd, ...)
|
||||
return function(_, ...)
|
||||
return fd_value(dfd.fd, ...)
|
||||
end
|
||||
end})
|
||||
end}
|
||||
|
||||
function io.dup(fd)
|
||||
return setmetatable({fd=fd,_closed=false}, dup_mt)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user