Merge branch 'master-MC1.10' of github.com:MightyPirates/OpenComputers into master-MC1.11

This commit is contained in:
Florian Nücke 2017-04-02 16:28:48 +02:00
commit 44e3b0ee46
8 changed files with 27 additions and 25 deletions

View File

@ -1,4 +1,7 @@
function loadfile(filename, mode, env)
if filename:sub(1,1) ~= "/" then
filename = (os.getenv("PWD") or "/") .. "/" .. filename
end
local handle, reason = require("filesystem").open(filename)
if not handle then
return nil, reason

View File

@ -1,4 +1,4 @@
alias l="ls -lh"
alias l="ls -lhp"
alias ..="cd .."
alias df="df -h"

View File

@ -20,17 +20,13 @@ function event.register(key, callback, interval, times)
local handler =
{
key = key,
times = times or 0,
times = times or math.huge,
callback = callback,
interval = interval or math.huge,
}
handler.timeout = computer.uptime() + handler.interval
if not interval then
handler.times = math.huge
end
local id = 0
repeat
id = id + 1
@ -60,8 +56,7 @@ local function dispatch(...)
-- nil keys match anything
local key = handler.key
key = (key == nil and signal) or key
if key == signal or time >= handler.timeout then
if (signal and key == signal) or time >= handler.timeout then
-- push ticks to end of list (might be slightly faster to fire them last)
table.insert(eligable, select(handler.key and 1 or 2, 1, {handler.callback, id}))
@ -160,7 +155,7 @@ function event.listen(name, callback)
return false
end
end
return event.register(name, callback, nil, nil)
return event.register(name, callback)
end
function event.onError(message)

View File

@ -27,6 +27,9 @@ keyboard.keys = {
tab = 0x0F,
up = 0xC8,
["end"] = 0xCF,
enter = 0x1C,
tab = 0x0F,
numpadenter = 0x9C,
}
-- Create inverse mapping for name lookup.

View File

@ -40,7 +40,7 @@ local function findFile(name, ext)
for file in list do
files[file] = true
end
if ext and unicode.sub(name, -(1 + unicode.len(ext))) == "." .. ext then
if ext and name:sub(-(1 + ext:len())) == "." .. ext then
-- Name already contains extension, prioritize.
if files[name] then
return true, fs.concat(dir, name)
@ -58,10 +58,10 @@ local function findFile(name, ext)
end
return false
end
if unicode.sub(name, 1, 1) == "/" then
if name:sub(1, 1) == "/" then
local found, where = findIn("/")
if found then return where end
elseif unicode.sub(name, 1, 2) == "./" then
elseif name:sub(1, 2) == "./" then
local found, where = findIn(shell.getWorkingDirectory())
if found then return where end
else
@ -162,7 +162,7 @@ function shell.resolve(path, ext)
return nil, "file not found"
end
else
if unicode.sub(path, 1, 1) == "/" then
if path:sub(1, 1) == "/" then
return fs.canonical(path)
else
return fs.concat(shell.getWorkingDirectory(), path)
@ -198,13 +198,13 @@ function shell.parse(...)
if not doneWithOptions and type(param) == "string" then
if param == "--" then
doneWithOptions = true -- stop processing options at `--`
elseif unicode.sub(param, 1, 2) == "--" then
elseif param:sub(1, 2) == "--" then
if param:match("%-%-(.-)=") ~= nil then
options[param:match("%-%-(.-)=")] = param:match("=(.*)")
else
options[unicode.sub(param, 3)] = true
options[param:sub(3)] = true
end
elseif unicode.sub(param, 1, 1) == "-" and param ~= "-" then
elseif param:sub(1, 1) == "-" and param ~= "-" then
for j = 2, unicode.len(param) do
options[unicode.sub(param, j, j)] = true
end

View File

@ -325,10 +325,11 @@ function term.readKeyboard(ops)
hints.cache = nil
local ctrl = kb.isControlDown(address)
if ctrl and code == keys.d then return
elseif char == 9 then
elseif code == keys.tab then
hints.cache = backup_cache
term.internal.tab(input,hints)
elseif char == 13 and filter(input) then
elseif (code == keys.enter or code == keys.numpadenter)
and filter(input) then
input:move(math.huge)
if db ~= false then
draw("\n")
@ -343,8 +344,8 @@ function term.readKeyboard(ops)
elseif code == keys["end"] then input:move( math.huge)
elseif code == keys.back then c = -1
elseif code == keys.delete then c = 0
elseif char >= 32 then c = unicode.char(char)
elseif ctrl and char == "w"then -- TODO: cut word
elseif char >= 32 then c = unicode.char(char)
else hints.cache = backup_cache -- ignored chars shouldn't clear hint cache
end
end

View File

@ -43,11 +43,11 @@ local function stat(names, index)
local info = {}
info.key = name
info.path = name:sub(1, 1) == "/" and "" or names.path
info.name = ops.p and name or name:gsub("/+$", "")
info.sort_name = info.name:gsub("^%.","")
info.full_path = fs.concat(info.path, info.name)
info.isLink, info.link = fs.isLink(info.full_path)
info.full_path = fs.concat(info.path, name)
info.isDir = fs.isDirectory(info.full_path)
info.name = name:gsub("/+$", "") .. (ops.p and info.isDir and "/" or "")
info.sort_name = info.name:gsub("^%.","")
info.isLink, info.link = fs.isLink(info.full_path)
info.size = info.isLink and 0 or fs.size(info.full_path)
info.time = fs.lastModified(info.full_path)
info.fs = fs.get(info.full_path)

View File

@ -157,7 +157,7 @@ function --[[@delayloaded-start@]] lib.where(tbl,p,f,l)
end,f,l)
end --[[@delayloaded-end@]]
function --[[@delayloaded-start@]] lib.concat(...)
function lib.concat(...)
local r,rn,k={},0
for _,tbl in ipairs({...})do
if type(tbl)~='table'then
@ -171,7 +171,7 @@ function --[[@delayloaded-start@]] lib.concat(...)
end
r.n=k and rn or nil
return r
end --[[@delayloaded-end@]]
end
-- works with pairs on tables
-- returns the kv pair, or nil and the number of pairs iterated