mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Merge branch 'master-MC1.7.10' of https://github.com/Kubuxu/OpenComputers into master-MC1.7.10
This commit is contained in:
commit
2b0da714c7
@ -2,15 +2,21 @@ local event = require "event"
|
|||||||
local component = require "component"
|
local component = require "component"
|
||||||
local keyboard = require "keyboard"
|
local keyboard = require "keyboard"
|
||||||
|
|
||||||
|
local args = {...}
|
||||||
|
|
||||||
local interactive = io.output() == io.stdout
|
local interactive = io.output() == io.stdout
|
||||||
local color, isPal, evt
|
local color, isPal, evt
|
||||||
if interactive then
|
if interactive then
|
||||||
color, isPal = component.gpu.getForeground()
|
color, isPal = component.gpu.getForeground()
|
||||||
end
|
end
|
||||||
io.write("Press 'q' to exit\n")
|
io.write("Press 'Ctrl-C' to exit\n")
|
||||||
pcall(function()
|
pcall(function()
|
||||||
repeat
|
repeat
|
||||||
evt = table.pack(event.pull())
|
if #args > 0 then
|
||||||
|
evt = table.pack(event.pullMultiple("interrupted", table.unpack(args)))
|
||||||
|
else
|
||||||
|
evt = table.pack(event.pull())
|
||||||
|
end
|
||||||
if interactive then component.gpu.setForeground(0xCC2200) end
|
if interactive then component.gpu.setForeground(0xCC2200) end
|
||||||
io.write("[" .. os.date("%T") .. "] ")
|
io.write("[" .. os.date("%T") .. "] ")
|
||||||
if interactive then component.gpu.setForeground(0x44CC00) end
|
if interactive then component.gpu.setForeground(0x44CC00) end
|
||||||
@ -25,7 +31,7 @@ pcall(function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
io.write("\n")
|
io.write("\n")
|
||||||
until evt[1] == "key_down" and evt[4] == keyboard.keys.q
|
until evt[1] == "interrupted"
|
||||||
end)
|
end)
|
||||||
if interactive then
|
if interactive then
|
||||||
component.gpu.setForeground(color, isPal)
|
component.gpu.setForeground(color, isPal)
|
||||||
|
@ -4,19 +4,6 @@ local keyboard = require("keyboard")
|
|||||||
local event, listeners, timers = {}, {}, {}
|
local event, listeners, timers = {}, {}, {}
|
||||||
local lastInterrupt = -math.huge
|
local lastInterrupt = -math.huge
|
||||||
|
|
||||||
local function matches(signal, name, filter)
|
|
||||||
if name and not (type(signal[1]) == "string" and signal[1]:match(name))
|
|
||||||
then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
for i = 1, filter.n do
|
|
||||||
if filter[i] ~= nil and filter[i] ~= signal[i + 1] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function call(callback, ...)
|
local function call(callback, ...)
|
||||||
local result, message = pcall(callback, ...)
|
local result, message = pcall(callback, ...)
|
||||||
if not result and type(event.onError) == "function" then
|
if not result and type(event.onError) == "function" then
|
||||||
@ -64,6 +51,45 @@ local function tick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function createPlainFilter(name, ...)
|
||||||
|
local filter = table.pack(...)
|
||||||
|
if name == nil and filter.n == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
local signal = table.pack(...)
|
||||||
|
if name and not (type(signal[1]) == "string" and signal[1]:match(name)) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for i = 1, filter.n do
|
||||||
|
if filter[i] ~= nil and filter[i] ~= signal[i + 1] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function createMultipleFilter(...)
|
||||||
|
local filter = table.pack(...)
|
||||||
|
if filter.n == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
local signal = table.pack(...)
|
||||||
|
if type(signal[1]) ~= "string" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for i = 1, filter.n do
|
||||||
|
if filter[i] ~= nil and signal[1]:match(filter[i]) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
function event.cancel(timerId)
|
function event.cancel(timerId)
|
||||||
@ -118,28 +144,50 @@ end
|
|||||||
|
|
||||||
function event.pull(...)
|
function event.pull(...)
|
||||||
local args = table.pack(...)
|
local args = table.pack(...)
|
||||||
local seconds, name, filter
|
|
||||||
if type(args[1]) == "string" then
|
if type(args[1]) == "string" then
|
||||||
name = args[1]
|
return event.pullFiltered(createPlainFilter(...))
|
||||||
filter = table.pack(table.unpack(args, 2, args.n))
|
|
||||||
else
|
else
|
||||||
checkArg(1, args[1], "number", "nil")
|
checkArg(1, args[1], "number", "nil")
|
||||||
checkArg(2, args[2], "string", "nil")
|
checkArg(2, args[2], "string", "nil")
|
||||||
seconds = args[1]
|
return event.pullFiltered(args[1], createPlainFilter(select(2, ...)))
|
||||||
name = args[2]
|
|
||||||
filter = table.pack(table.unpack(args, 3, args.n))
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local hasFilter = name ~= nil
|
function event.pullMultiple(...)
|
||||||
if not hasFilter then
|
local seconds
|
||||||
for i = 1, filter.n do
|
local args
|
||||||
hasFilter = hasFilter or filter[i] ~= nil
|
if type(...) == "number" then
|
||||||
|
seconds = ...
|
||||||
|
args = table.pack(select(2,...))
|
||||||
|
for i=1,args.n do
|
||||||
|
checkArg(i+1, args[i], "string", "nil")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
args = table.pack(...)
|
||||||
|
for i=1,args.n do
|
||||||
|
checkArg(i, args[i], "string", "nil")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return event.pullFiltered(seconds, createMultipleFilter(table.unpack(args, 1, args.n)))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function event.pullFiltered(...)
|
||||||
|
local args = table.pack(...)
|
||||||
|
local seconds, filter
|
||||||
|
|
||||||
|
if type(args[1]) == "function" then
|
||||||
|
filter = args[1]
|
||||||
|
else
|
||||||
|
checkArg(1, args[1], "number", "nil")
|
||||||
|
checkArg(2, args[2], "function", "nil")
|
||||||
|
seconds = args[1]
|
||||||
|
filter = args[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
local deadline = seconds and
|
local deadline = seconds and
|
||||||
(computer.uptime() + seconds) or
|
(computer.uptime() + seconds) or
|
||||||
(hasFilter and math.huge or 0)
|
(filter and math.huge or 0)
|
||||||
repeat
|
repeat
|
||||||
local closest = seconds and deadline or math.huge
|
local closest = seconds and deadline or math.huge
|
||||||
for _, timer in pairs(timers) do
|
for _, timer in pairs(timers) do
|
||||||
@ -154,9 +202,15 @@ function event.pull(...)
|
|||||||
lastInterrupt = computer.uptime()
|
lastInterrupt = computer.uptime()
|
||||||
error("interrupted", 0)
|
error("interrupted", 0)
|
||||||
end
|
end
|
||||||
if not (seconds or hasFilter) or matches(signal, name, filter) then
|
if event.shouldSoftInterrupt() and (filter == nil or filter("interrupted", computer.uptime() - lastInterrupt)) then
|
||||||
|
local awaited = computer.uptime() - lastInterrupt
|
||||||
|
lastInterrupt = computer.uptime()
|
||||||
|
return "interrupted", awaited
|
||||||
|
end
|
||||||
|
if not (seconds or filter) or filter == nil or filter(table.unpack(signal, 1, signal.n)) then
|
||||||
return table.unpack(signal, 1, signal.n)
|
return table.unpack(signal, 1, signal.n)
|
||||||
end
|
end
|
||||||
|
|
||||||
until computer.uptime() >= deadline
|
until computer.uptime() >= deadline
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,6 +221,12 @@ function event.shouldInterrupt()
|
|||||||
keyboard.isKeyDown(keyboard.keys.c)
|
keyboard.isKeyDown(keyboard.keys.c)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function event.shouldSoftInterrupt()
|
||||||
|
return computer.uptime() - lastInterrupt > 1 and
|
||||||
|
keyboard.isControlDown() and
|
||||||
|
keyboard.isKeyDown(keyboard.keys.c)
|
||||||
|
end
|
||||||
|
|
||||||
function event.timer(interval, callback, times)
|
function event.timer(interval, callback, times)
|
||||||
checkArg(1, interval, "number")
|
checkArg(1, interval, "number")
|
||||||
checkArg(2, callback, "function")
|
checkArg(2, callback, "function")
|
||||||
|
@ -2,5 +2,12 @@ NAME
|
|||||||
dmesg - display messages(events)
|
dmesg - display messages(events)
|
||||||
|
|
||||||
SYNOPIS
|
SYNOPIS
|
||||||
dmesg
|
dmesg [EVENT]...
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
dmesg
|
||||||
|
Shows all events.
|
||||||
|
|
||||||
|
dmesg touch
|
||||||
|
Shows only "touch" events.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user