-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.tin
75 lines (58 loc) · 1.69 KB
/
events.tin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#nop Not my work, I don' know who originally wrote this -gaidin;
#VAR _events {};
#ALIAS _event_tmp_ali #NOP;
#NOP event_register eventName handlerName action
#NOP adds action to the eventName event under the tag handlerName.
#ALIAS event_register
{
#VAR _events[%1][%2] {%3};
}
#NOP event_oneshot eventName handlerName action
#NOP adds action to the eventName event, removes after being called
#alias {event_oneshot}
{
#var _events[%1][%2] {event_remove_specific {%1} {%2};%3};
};
#NOP event_remove_event eventName
#NOP removes eventName completely
#ALIAS event_remove_event
{
#LINE SUBSTITUTE {VARIABLE} #UNVAR _events[%1];
}
#NOP event_remove_handler handlerName
#NOP removes handlerName from all events
#ALIAS event_remove_handler
{
#FOREACH {*{_events[]}} {sublist}
{
#LINE SUBSTITUTE {VARIABLE} #UNVAR _events[$sublist][%1];
#IF {"${_events[$sublist]}" == ""} {#LINE SUBSTITUTE {VARIABLE} #UNVAR _events[$sublist]};
}
}
#NOP event_remove_specific eventName handlerName
#NOP removes handlerName from eventName
#ALIAS event_remove_specific
{
#LINE SUBSTITUTE {VARIABLE} #UNVAR _events[%1][%2];
#IF {"${_events[%1]}" == ""} {#LINE SUBSTITUTE {VARIABLE} #UNVAR _events[%1]};
}
#NOP event_eval is a helper function that allows dynamic alias definitions.
#ALIAS event_eval
{
#ALIAS _event_tmp_ali {%1};
_event_tmp_ali %2;
#ALIAS _event_tmp_ali #NOP;
}
#NOP event_raise eventName args
#NOP calls all actions for eventName with args
#ALIAS event_raise
{
#nop #IF {"$flags[debug][events]" != ""} {#ECHO {EVENT: %0}};
#FOREACH {*{_events[%1][]}} {handler}
{
#IF {&{_events[%1][$handler]} != 0}
{
event_eval {${_events[%1][$handler]}} {%0};
};
};
};