-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_Bound.ahk
49 lines (39 loc) · 1.03 KB
/
class_Bound.ahk
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
Class Bound {
Class Func { ; cf. https://github.com/Lexikos/xHotkey.ahk/blob/master/xHotkey_test.ahk
__New(_fn, _args*) {
if not (_v:=Bound.Func._isCallableObject(_fn))
throw ErrorLevel:=1
else this.fn := (_v < 1) ? _fn.bind(_args*) : ObjBindMethod(_fn, _args.removeAt(1), _args*)
}
__Call(_callee) {
if (StrReplace(_callee, "call", "") = "") {
_fn := this.fn
return %_fn%()
}
}
_isCallableObject(ByRef _callback) {
if (IsFunc(_callback)) {
((_callback.minParams = "") && _callback:=Func(_callback))
return -1
} else if (IsObject(_callback)) ; _callback.base.hasKey("__Call")
return 1
else return 0
}
Class Iterator {
__New(_fn, _args*) {
this.callableObject := new Bound.Func(_fn, _args*)
}
setPeriod(_period) {
if (_f:=this.callableObject)
SetTimer, % _f, % _period
}
delete() {
if not (_f:=this.callableObject)
return
SetTimer, % _f, Off
SetTimer, % _f, Delete
return this.callableObject := ""
}
}
}
}