forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheat-sheet.yml
More file actions
567 lines (485 loc) · 12.7 KB
/
cheat-sheet.yml
File metadata and controls
567 lines (485 loc) · 12.7 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# This YAML is used to generate cheat sheets for either the LiveCode
# language, or for transitioning between an alternative scripting
# language and LiveCode.
# Each element of the content array must have a title element, which is
# used for the relevant section, and an lc element which contains the
# relevant LiveCode script. Each element containing both lc and another
# language (currently either py for Python or js for Javascript) will
# place the code side by side in the generated cheat sheet PDF, under
# the heading given in the title.
# If there is a text element, this text will precede the code for the
# section.
content:
- title: "Comments"
text: |
Comments allow you to add explanations and annotations to your code.
lc: |
-- these
# are
// all
/* commented
out */
lcb: |
-- these
// are
/* commented
out */
py: |
# this is commented out
js: |
// These
/* are
commented
out */
- title: "Literals"
text: |
A literal is a notation for creating a particular type of value.
lcb: |
"string literal"
["list", "of", "literals"]
{"array": "literal"}
py: |
"string literal"
'string literal'
["list", "of", "literals"]
{"dictionary": "literal"}
js: |
"string literal"
'string literal'
["array", "of", "literals"]
{"object": "literal"}
- title: "Variables"
text: |
Variables are used to to store information, the stored value can be changed or accessed when you need it.
lc: |
local tVar
put "str" into tVar
put 1 into tVar
put "val" into tVar["key"]
lcb: |
variable tVar
put "str" into tVar
put 1 into tVar
variable tArr as Array
put "val" into tArr["key"]
py: |
var = "str"
var = 1
var["key"] = "val"
js: |
var myVar;
myVar = "str";
myVar = 1;
var arr = {};
arr["key"] = "val";
- title: "Constants"
text: |
Constants store a value that is defined at the point of declaration and never changes.
lc: |
constant kFoo = 15
lcb: |
constant kFoo is 15
js: |
const FOO = 15;
- title: "Control Structures"
text: |
Control structures are used to control what code is executed and how many times.
lc: |
repeat for each char tChar in tVar
end repeat
repeat 10
end repeat
repeat with x = 1 to 10
end repeat
repeat while x > 1
subtract 1 from x
end repeat
if true then ... else ...
if tVar then
else if tOther then
else
end if
switch tVar
case "a"
break
default
break
end switch
lcb: |
repeat for each char tChar in tVar
end repeat
repeat 10 times
end repeat
repeat with tX from 1 up to 10
end repeat
repeat while tX > 1
subtract 1 from tX
end repeat
if tVar then
else if tOther then
else
end if
py: |
for x in tVar:
# do things
for x in range(10):
# do things
while x > 1:
x -= 1
if tVar:
elif tOther:
else:
js: |
for (var i=0; i < text.length; i++) {
char = text.charAt(i);
}
for (var i=0; i < 10; i++) {
}
while (x > 1) {
x--;
}
if (value) {
} else if (other) {
} else {
}
switch (value) {
case "a":
break;
default:
break;
}
- title: "Operators"
text: |
Operators are ways of combining values such as boolean values, numbers or strings, to produce other values.
lc: |
// Logical
true and false is false
true or false is true
not false is true
// String
"foo" & "bar" is "foobar"
"foo" && "bar" is "foo bar"
"string" begins with "st"
"string" ends with "g"
// Chunks
char 5 of "string" is "n"
item 3 of "a,b,c" is "c"
word 1 of "hi there" is "hi"
line 2 of "a" & return & "b" is "b"
// Compound chunks
char 1 of item 1 of line 1 of "a,b,c" is "a"
lcb: |
// Logical
true and false is false
true or false is true
not false is true
// String
"foo" & "bar" is "foobar"
"foo" && "bar" is "foo bar"
"string" begins with "st"
"string" ends with "g"
// Chunks
char 5 of "string" is "n"
split "a,b,c" by "," into tItems
tItems[3] is "c"
split "hi there" by " " into tWords
tWords[1] is "hi"
split "a\nb" by "\n" into tLines
tLines[2] is "b"
split "a,b,c" by "\n" into tLines
split tLines by "," into tItems
char 1 of tItems[1] is "a"
py: |
# Logical
true and false == false
true or false == true
!false == true
# String
"foo" + "bar" == "foobar"
strs = ['foo','bar']
' '.join(strs) == "foo bar"
"string".startswith("st")
"string".endswith("g")
# Chunks
"string"[4:5] == "n"
items = "a,b,c".split(",")
items[2] == "c"
words = "hi there".split(" ")
words[0] == "hi"
lines = "a\nb".split("\n")
lines[1] == "b"
lines = "a,b,c".split("\n")
items = lines[1].split(",")
items[1][0:1] == "a"
js: |
// Logical
true && false == false
true || false == true
!false == true
// String
"foo" + "bar" == "foobar"
var strs = ['foo','bar'];
strs.join(" ") == "foo bar"
"string".startsWith("st");
"string".endsWith("g");
// Chunks
"string".charAt(4) == "n"
var items = "a,b,c".split(",");
items[2] == "c"
var words = "hi there".split(" ");
words[0] == "hi"
var lines = "a\nb".split("\n");
lines[2] == "b"
var lines = "a,b,c".split("\n")
var items = lines[1].split(",")
items[1].charAt(0) == "a"
- title: "String Processing"
text: |
These examples show how string values can be manipulated.
lc: |
// General
put "a" before tVar
delete char 1 of tVar
replace "_" with "-" in tVar
// Regex
matchText("1", "([0-9])", tN) is true
tN is 1
filter lines of tVar with regex pattern tPattern
lcb: |
// General
put "a" before tVar
delete char 1 of tVar
replace "_" with "-" in tVar
py: |
# General
var = 'a' + var
var = var[1:]
var.replace("_", "-")
# Regex
found = re.match('([0-9])', '1')
num = tMatch.group(1)
for line in var:
if re.match(pattern, line):
filtered.push(line)
var = '\n'.join(filtered)
js: |
# General
str = 'a' + str;
str = str.slice(1);
str = str.replace("_", "-")
# Regex
var found = /[0-9]/.exec("1");
var num = found[1];
str.split("\n").filter(function(elem) {
return pattern.exec(elem) != NULL;
});
- title: "Array Processing"
text: |
These examples show how array values can be manipulated.
lc: |
// Split / combine
put "a,b,c" into tVar
split tVar by ","
tVar[2] is "b"
combine tVar with ","
tVar is "a,b,c"
// Iteration
repeat for each key tKey in tArray
-- Do something with tArray[tKey]
end repeat
repeat for each element tElement in tArray
end repeat
// Length
the number of elements in tArray
lcb: |
// Split / combine
put "a,b,c" into tVar
split tVar by ","
tVar[2] is "b"
combine tVar with ","
tVar is "a,b,c"
// Iteration
repeat for each key tKey in tArray
-- Do something with tArray[tKey]
end repeat
repeat for each element tElement in tArray
end repeat
// Length
the number of elements in tArray
py: |
# Split / combine
var = "a,b,c".split(",")
var[1] is "b"
','.join(var)
var == "a,b,c"
# Iteration
for key in array:
# do something with array[key]
# Length
len(array)
js: |
# Split / combine
var list = "a,b,c".split(",")
list[1] is "b"
list = list.join(",");
list == "a,b,c"
for (var key in array) {
# Do something with array[key];
}
# Length
array.length();
- title: "Sorting"
text: |
These examples show how to sort items and lists.
lc: |
local tList
put "5,2,3,1,4" into tList
sort items of tList ascending numeric
-> tList is "1,2,3,4,5"
sort items of tList descending numeric
-> tList is "5,4,3,2,1"
local tData
put "6,1:8,3:2,2" into tData
set the lineDelimiter to ":"
sort lines of tData ascending numeric by item 2 of each
-> tData is "6,1:2,2:8,3"
lcb: |
variable tList
put [5,2,3,1,4] into tList
sort tList in ascending numeric order
-> tList is [1,2,3,4,5]
sort tList in descending numeric order
-> tList is [5,4,3,2,1]
public handler DoSort(in pLeft, in pRight) returns Integer
return pLeft[2] - pRight[2]
end handler
variable tData as List
put [[6, 1], [8, 3], [2, 2]] into tData
sort tData using handler DoSort
-> tData is [[6, 1], [2, 2], [8, 3]]
py: |
list = [5, 2, 3, 1, 4]
sorted(list) == [1, 2, 3, 4, 5]
sorted(list, reverse=True) == [5, 4, 3, 2, 1]
data = [(6, 1), (8, 3), (2, 2)]
sorted(data, key=itemgetter(2)) == [(6, 1), (2, 2), (8, 3)]
js: |
var list = [5, 2, 3, 1, 4]
list.sort();
-> list == [1, 2, 3, 4, 5]
list.reverse();
-> list == [5, 4, 3, 2, 1]
var data = [[6, 1], [8, 3], [2, 2]];
data.sort(function(a,b) {
return a[2] - b[2]
});
-> data == [[6, 1], [2, 2], [8, 3]]
- title: "Files & Processes"
text: |
These examples show how to read from and write to files and processes.
lc: |
get url("file:/" & tPath)
put "" into url("file:/" & tPath)
open process tProc
read from process tProc for 5
close process tProc
lcb: |
get the contents of file tPath
set the contents of file tPath to ""
py: |
open(tPath).read()
open(tPath).write("")
process = subprocess.Popen([tProc], stdout=subprocess.PIPE)
while True:
process.wait()
data = process.stdout.read(5)
if data:
break
- title: "User Input / Notification"
text: |
These examples show how to pop up information dialogs, or prompts for user input.
lc: |
ask "What is your name?"
put it into tName
answer "Something"
py: |
dlg = wx.TextEntryDialog(None, "What is your name?", defaultValue=default_value)
dlg.ShowModal()
name = dlg.GetValue()
dlg.Destroy()
dlg = wx.MessageDialog(None, "Something", caption, wx.OK)
result = dlg.ShowModal()
dlg.Destroy()
js: |
var name = prompt("What is your name?");
alert("Something");
- title: "Custom Handlers"
text: |
A custom handler is a function or command that you define yourself.
lc: |
function foo pParam
end foo
// get foo(tVar)
command bar pParam
end bar
// bar 5
lcb: |
handler foo(in pParam)
end foo
// get foo(tVar)
// foo 5
py: |
def foo(param):
# return something
# foo(var)
js: |
function foo(param) {
}
// foo(value)
- title: "Event Handlers"
text: |
An event handler is a hander that is triggered when an event occurs, such as the use of the mouse or keyboard.
lc: |
// Mouse
on mouseUp pButton
end mouseUp
on mouseDown pButton
end mouseDown
on mouseMove
end mouseMove
// Keyboard
on keyDown pKey
end keyDown
on keyUp pKey
end keyUp
lcb: |
// Mouse
handler OnMouseUp()
get the click button
end handler
handler OnMouseDown()
get the click button
end handler
handler OnMouseMove()
end handler
// Keyboard
handler OnKeyPress(in pText)
end handler
js: |
# Mouse
function handleMouseUp {
}
<button onmouseup="handleMouseUp" />
function handleMouseDown {
}
<button onmousedown="handleMouseDown" />
function handleMouseMove {
}
<div onmousemove="handleMouseMove" />
# Keyboard
function handleKeyUp {
}
<input onkeyup="handleKeyUp" />
function handleKeyDown {
}
<input onkeydown="handleKeyDown" />