1-- @docvars @{
2
3-- root widget
4rootWidget = g_ui.getRootWidget()
5modules = package.loaded
6
7-- G is used as a global table to save variables in memory between reloads
8G = G or {}
9
10-- @}
11
12-- @docfuncs @{
13
14function scheduleEvent(callback, delay)
15 local desc = "lua"
16 local info = debug.getinfo(2, "Sl")
17 if info then
18 desc = info.short_src .. ":" .. info.currentline
19 end
20 local event = g_dispatcher.scheduleEvent(desc, callback, delay)
21 -- must hold a reference to the callback, otherwise it would be collected
22 event._callback = callback
23 return event
24end
25
26function addEvent(callback, front)
27 local desc = "lua"
28 local info = debug.getinfo(2, "Sl")
29 if info then
30 desc = info.short_src .. ":" .. info.currentline
31 end
32 local event = g_dispatcher.addEvent(desc, callback, front)
33 -- must hold a reference to the callback, otherwise it would be collected
34 event._callback = callback
35 return event
36end
37
38function cycleEvent(callback, interval)
39 local desc = "lua"
40 local info = debug.getinfo(2, "Sl")
41 if info then
42 desc = info.short_src .. ":" .. info.currentline
43 end
44 local event = g_dispatcher.cycleEvent(desc, callback, interval)
45 -- must hold a reference to the callback, otherwise it would be collected
46 event._callback = callback
47 return event
48end
49
50function periodicalEvent(eventFunc, conditionFunc, delay, autoRepeatDelay)
51 delay = delay or 30
52 autoRepeatDelay = autoRepeatDelay or delay
53
54 local func
55 func = function()
56 if conditionFunc and not conditionFunc() then
57 func = nil
58 return
59 end
60 eventFunc()
61 scheduleEvent(func, delay)
62 end
63
64 scheduleEvent(function()
65 func()
66 end, autoRepeatDelay)
67end
68
69function removeEvent(event)
70 if event then
71 event:cancel()
72 event._callback = nil
73 end
74end
75
76-- @}