You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libscript/src/array.mlc
+135-6Lines changed: 135 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,35 @@ public foreign handler MCArrayStoreElementOfCaseless(in Value as any, inout Targ
15
15
16
16
public foreign handler MCArrayEvalEmpty(out Value as array) as undefined binds to "<builtin>"
17
17
18
+
public foreign handler MCArrayRepeatForEachElement(inout Iterator as optional pointer, out Iterand as any, in Container as array) as bool binds to "<builtin>"
19
+
public foreign handler MCArrayRepeatForEachKey(inout Iterator as optional pointer, out Iterand as string, in Container as array) as bool binds to "<builtin>"
20
+
18
21
--
19
22
20
23
/*
21
24
Summary: Returns the keys of an array.
22
25
Target: An expression which evaluates to an array.
23
26
output: A list whose elements are the keys of <Target>.
24
-
Note that the list is not ordered in any way.
27
+
28
+
Example:
29
+
variable tArray as array
30
+
put the empty array into tArray
31
+
put "value1" into tArray["key1"]
32
+
put "value2" into tArray["key2"]
33
+
put "value3" into tArray["key3"]
34
+
35
+
variable tKeys as list
36
+
put the keys of tArray into tKeys
37
+
sort tKeys in ascending order
38
+
39
+
variable tKeysString as string
40
+
combine tKeys with "," into tKeysString
41
+
// tKeysString is "key1,key2,key3"
42
+
43
+
References:com.livecode.sort
44
+
45
+
Description:
46
+
>*Note:* The resulting list is not necessarily ordered in any way. Use the <com.livecode.sort> library to sort the keys.
25
47
*/
26
48
27
49
syntax KeysOf is prefix operator with precedence 2
@@ -34,7 +56,24 @@ end syntax
34
56
Summary: Returns the elements of an array.
35
57
Target: An expression which evaluates to an array.
36
58
output: A list whose elements are the elements of <Target>.
37
-
Note that the list is not ordered in any way.
59
+
60
+
Example:
61
+
variable tArray as array
62
+
put the empty array into tArray
63
+
put 1 into tArray["key1"]
64
+
put 2 into tArray["key2"]
65
+
put 3 into tArray["key3"]
66
+
67
+
variable tElements as list
68
+
put the elements of tArray into tElements
69
+
sort tElements in ascending numeric order
70
+
71
+
// tElements is [1, 2, 3]
72
+
73
+
References:com.livecode.sort
74
+
75
+
Description:
76
+
>*Note:* The resulting list is not necessarily ordered in any way. Use the <com.livecode.sort> library to sort the elements.
38
77
*/
39
78
40
79
syntax ElementsOf is prefix operator with precedence 2
@@ -48,6 +87,16 @@ end syntax
48
87
/*
49
88
Summary: Returns the number of elements in <Target>
50
89
Target: An expression which evaluates to an array.
90
+
91
+
Example:
92
+
variable tArray as array
93
+
put the empty array into tArray
94
+
put 1 into tArray["key1"]
95
+
put 2 into tArray["key2"]
96
+
put 3 into tArray["key3"]
97
+
98
+
variable tVar as integer
99
+
put the number of elements in tArray into tVar -- tVar contains 3
51
100
*/
52
101
53
102
syntax CountElementsOf is prefix operator with precedence 1
@@ -94,11 +143,19 @@ end syntax
94
143
/*
95
144
96
145
Summary: Designates the element with key <Key> in <Target>.
97
-
Key: An expression which evaluates to an integer, string, or list of integers.
146
+
Index: An expression which evaluates to a string.
98
147
Target: An expression which evaluates to an array.
99
-
output: Either locates the element container with the given key for use as the target
100
-
container of another operation, or evaluates the element with the given key
101
-
as the source of another operation.
148
+
149
+
Example:
150
+
variable tArray as array
151
+
put the empty array into tArray
152
+
put "value" into tArray["key"]
153
+
154
+
variable tVar as string
155
+
put tArray["key"] into tVar -- tVar contains "value"
156
+
157
+
Description:
158
+
Either locates the element container with the given key for use as the target container of another operation, or evaluates the element with the given key as the source of another operation.
102
159
*/
103
160
104
161
syntax SingletonElementOf is postfix operator with precedence 1
@@ -110,10 +167,82 @@ end syntax
110
167
111
168
--
112
169
170
+
/*
171
+
172
+
Summary: Designates the array with zero elements
173
+
174
+
Example:
175
+
variable tVar as array
176
+
variable tCount as int
177
+
put the empty array into tVar
178
+
put the number of elements in tVar into tCount -- tCount is 0
179
+
180
+
Description:
181
+
Use ```the empty array``` to initialise an array variable.
182
+
183
+
*/
184
+
113
185
syntax EmptyArray is expression
114
186
"the" "empty" "array"
115
187
begin
116
188
MCArrayEvalEmpty(output)
117
189
end syntax
118
190
191
+
--
192
+
193
+
/*
194
+
Summary: Repeat over the elements of an array.
195
+
Iterand: An expression of the form 'tVar in tArray'
0 commit comments