2011-11-07 01:14:51 +01:00
|
|
|
local eventId = 0
|
|
|
|
local eventsTable = { }
|
2011-08-14 19:45:25 +02:00
|
|
|
local orig = { scheduleEvent = scheduleEvent,
|
|
|
|
addEvent = addEvent }
|
|
|
|
|
|
|
|
-- fix original scheduleEvent
|
|
|
|
function scheduleEvent(func, delay)
|
2011-11-07 01:14:51 +01:00
|
|
|
eventId = eventId + 1
|
|
|
|
local id = eventId
|
|
|
|
local function proxyFunc()
|
2011-11-07 18:20:13 +01:00
|
|
|
if eventsTable[id] then
|
|
|
|
func()
|
|
|
|
eventsTable[id] = nil
|
|
|
|
end
|
2011-11-07 01:14:51 +01:00
|
|
|
end
|
|
|
|
eventsTable[id] = proxyFunc
|
|
|
|
orig.scheduleEvent(proxyFunc, delay)
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
|
2011-11-07 18:20:13 +01:00
|
|
|
-- FIXME: the event function can be collected
|
|
|
|
-- and the dispatcher would call an invalid function, generating an warning
|
2011-11-07 01:14:51 +01:00
|
|
|
function removeEvent(id)
|
|
|
|
if id and eventsTable[id] then
|
|
|
|
eventsTable[id] = nil
|
2011-11-07 18:20:13 +01:00
|
|
|
return true
|
2011-11-07 01:14:51 +01:00
|
|
|
end
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- fix original addEvent
|
|
|
|
function addEvent(func)
|
2011-11-07 18:20:13 +01:00
|
|
|
eventId = eventId + 1
|
|
|
|
local id = eventId
|
|
|
|
local function proxyFunc()
|
|
|
|
if eventsTable[id] then
|
|
|
|
func()
|
|
|
|
eventsTable[id] = nil
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
2011-11-07 18:20:13 +01:00
|
|
|
end
|
|
|
|
eventsTable[id] = proxyFunc
|
|
|
|
orig.addEvent(proxyFunc)
|
|
|
|
return id
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|