tibia-client/modules/corelib/globals.lua

61 lines
1.3 KiB
Lua
Raw Normal View History

2012-06-26 00:13:30 +02:00
-- @docvars @{
2012-06-26 00:13:30 +02:00
-- root widget
rootWidget = g_ui.getRootWidget()
modules = package.loaded
2012-01-05 02:28:29 +01:00
-- G is used as a global table to save variables in memory between reloads
G = G or {}
2012-06-26 00:13:30 +02:00
-- @}
2012-06-26 00:13:30 +02:00
-- @docfuncs @{
2012-02-06 20:19:47 +01:00
function scheduleEvent(callback, delay)
2012-06-26 00:13:30 +02:00
local event = g_dispatcher.scheduleEvent(callback, delay)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function addEvent(callback, front)
2012-06-26 00:13:30 +02:00
local event = g_dispatcher.addEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
2012-06-06 22:14:53 +02:00
function cycleEvent(callback, front)
2012-06-26 00:13:30 +02:00
local event = g_dispatcher.cycleEvent(callback, front)
2012-06-06 22:14:53 +02:00
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function periodicalEvent(eventFunc, conditionFunc, delay, autoRepeatDelay)
delay = delay or 30
autoRepeatDelay = autoRepeatDelay or delay
local func
func = function()
if conditionFunc and not conditionFunc() then
func = nil
return
end
eventFunc()
scheduleEvent(func, delay)
end
scheduleEvent(function()
func()
end, autoRepeatDelay)
end
function removeEvent(event)
if event then
event:cancel()
event._callback = nil
end
end
2012-06-26 00:13:30 +02:00
-- @}