implement remove event lua function

This commit is contained in:
Eduardo Bart
2011-11-06 22:14:51 -02:00
parent 4e0ca24cb7
commit 5b1b170165
2 changed files with 28 additions and 15 deletions

View File

@@ -1,28 +1,40 @@
local eventId = 1
local events = { }
local eventId = 0
local eventsTable = { }
local orig = { scheduleEvent = scheduleEvent,
addEvent = addEvent }
-- fix original scheduleEvent
function scheduleEvent(func, delay)
eventId = eventId + 1
local id = eventId + 1
local function proxyFunc()
eventId = eventId + 1
local id = eventId
local function proxyFunc()
if eventsTable[id] then
func()
table[id] = nil
end
table[id] = proxyFunc
orig.scheduleEvent(proxyFunc, delay)
eventsTable[id] = nil
end
end
eventsTable[id] = proxyFunc
orig.scheduleEvent(proxyFunc, delay)
return id
end
function removeEvent(id)
if id and eventsTable[id] then
eventsTable[id] = nil
end
end
-- fix original addEvent
function addEvent(func)
eventId = eventId + 1
local id = eventId + 1
local id = eventId
local function proxyFunc()
func()
table[id] = nil
if eventsTable[id] then
func()
eventsTable[id] = nil
end
end
table[id] = proxyFunc
eventsTable[id] = proxyFunc
orig.addEvent(proxyFunc)
return id
end