-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathTakingObjectsInOrder.ahk
103 lines (86 loc) · 1.9 KB
/
TakingObjectsInOrder.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
; Link: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=71786&sid=489e40d94f85686040c5a8b61b2ed202
; Author:
; Date:
; for: AHK_L
/*
*/
obj := new ScriptingDictionary
obj[3] := 1
obj[2] := 2
obj.B := 3
obj.b := 4
obj.a := 5
obj.A := 6
for k, v in obj
MsgBox,, Pairs, % k . ": " . v
keys := obj.Keys
for k, v in keys
MsgBox,, Keys, % v
values := obj.Items
for k, v in values
MsgBox,, Values, % v
obj.Delete("a")
MsgBox, % obj.HasKey("a")
MsgBox, % obj.HasKey("A")
class ScriptingDictionary
{
__New() {
this._dict_ := ComObjCreate("Scripting.Dictionary")
}
__Delete() {
this._dict_.RemoveAll()
this.SetCapacity("_dict_", 0)
this._dict_ := ""
}
__Set(key, value) {
if !(key == "_dict_") {
if !this._dict_.Exists(key)
this._dict_.Add(key, value)
else
this._dict_.Item(key) := value
Return value
}
}
__Get(key) {
if (key == "_dict_")
Return
if (key == "Keys" || key == "Items") {
keys := this._dict_[key]
arr := []
Loop % this._dict_.Count
arr.Push(keys[A_Index - 1])
Return arr
}
else
Return this._dict_.Item(key)
}
_NewEnum() {
Return new ScriptingDictionary._CustomEnum_(this._dict_)
}
class _CustomEnum_
{
__New(dict) {
this.i := -1
this.dict := dict
this.keys := this.dict.Keys()
this.items := this.dict.Items()
}
Next(ByRef k, ByRef v) {
if ( ++this.i = this.dict.Count() )
Return false
k := this.keys[this.i]
v := this.items[this.i]
Return true
}
}
Delete(key) {
if this._dict_.Exists(key) {
value := this._dict_.Item(key)
this._dict_.Remove(key)
}
Return value
}
HasKey(key) {
Return !!this._dict_.Exists(key)
}
}