Merge branch master-MC1.8.9 into master-MC1.9.4

This commit is contained in:
payonel 2017-09-28 11:23:28 -07:00
commit c5bb6221cb

View File

@ -42,25 +42,26 @@ computer.pullSignal = function(...) -- dispatch
end end
local event_data = table.pack(handlers(...)) local event_data = table.pack(handlers(...))
local signal = event_data[1] local signal = event_data[1]
local ids = {} local copy = {}
for id in pairs(handlers) do for id,handler in pairs(handlers) do
ids[#ids+1] = id copy[id] = handler
end end
for _,id in ipairs(ids) do for id,handler in pairs(copy) do
local handler = handlers[id]
-- timers have false keys -- timers have false keys
-- nil keys match anything -- nil keys match anything
if (handler.key == nil or handler.key == signal) or current_time >= handler.timeout then if (handler.key == nil or handler.key == signal) or current_time >= handler.timeout then
handler.times = handler.times - 1 handler.times = handler.times - 1
handler.timeout = current_time + handler.interval handler.timeout = current_time + handler.interval
if handler.times <= 0 then -- we have to remove handlers before making the callback in case of timers that pull
-- and we have to check handlers[id] == handler because callbacks may have unregistered things
if handler.times <= 0 and handlers[id] == handler then
handlers[id] = nil handlers[id] = nil
end end
-- call -- call
local result, message = pcall(handler.callback, table.unpack(event_data, 1, event_data.n)) local result, message = pcall(handler.callback, table.unpack(event_data, 1, event_data.n))
if not result then if not result then
pcall(event.onError, message) pcall(event.onError, message)
elseif message == false then elseif message == false and handlers[id] == handler then
handlers[id] = nil handlers[id] = nil
end end
end end