forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.mlc
More file actions
428 lines (335 loc) · 13.9 KB
/
engine.mlc
File metadata and controls
428 lines (335 loc) · 13.9 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
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/*
This library provides operations for interacting with LiveCode Script from LiveCode Builder.
Tags: Engine
Name: ScriptObject
Type: type
Summary: An opaque type corresponding to a LiveCode script object.
Syntax: ScriptObject
Description:
Use the <ResolveScriptObject|resolve script object>, or <MyScriptObject|my script object> to obtain an object of type <ScriptObject>
References: ResolveScriptObject(statement), MyScriptObject(expression)
*/
module com.livecode.engine
use com.livecode.foreign
public foreign type ScriptObject binds to "kMCEngineScriptObjectTypeInfo"
public foreign handler MCEngineExecResolveScriptObject(in pObjectId) returns ScriptObject binds to "<builtin>"
public foreign handler MCEngineEvalScriptObjectExists(in pObject as ScriptObject, out rExists as CBool) returns nothing binds to "<builtin>"
public foreign handler MCEngineEvalScriptObjectDoesNotExists(in pObject as ScriptObject, out rExists as CBool) returns nothing binds to "<builtin>"
public foreign handler MCEngineExecGetPropertyOfScriptObject(in pProperty as String, in pObject as ScriptObject) returns any binds to "<builtin>"
public foreign handler MCEngineExecSetPropertyOfScriptObject(in pProperty as String, in pObject as ScriptObject, in pValue as any) returns nothing binds to "<builtin>"
public foreign handler MCEngineEvalOwnerOfScriptObject(in pObject as ScriptObject, out rParent as ScriptObject) returns nothing binds to "<builtin>"
public foreign handler MCEngineEvalChildrenOfScriptObject(in pObject as ScriptObject, out rChildren as List) returns nothing binds to "<builtin>"
public foreign handler MCEngineExecSendToScriptObject(in pIsFunction as CBool, in pMessage as String, in pTarget as ScriptObject) returns any binds to "<builtin>"
public foreign handler MCEngineExecSendToScriptObjectWithArguments(in pIsFunction as CBool, in pMessage as String, in pTarget as ScriptObject, in pArguments as optional List) returns any binds to "<builtin>"
public foreign handler MCEngineExecPostToScriptObject(in pMessage as String, in pTarget as ScriptObject) returns nothing binds to "<builtin>"
public foreign handler MCEngineExecPostToScriptObjectWithArguments(in pMessage as String, in pTarget as ScriptObject, in pArguments as optional List) returns nothing binds to "<builtin>"
public foreign handler MCEngineEvalMessageWasHandled(out pHandled as CBool) returns nothing binds to "<builtin>"
public foreign handler MCEngineEvalMessageWasNotHandled(out pHandled as CBool) returns nothing binds to "<builtin>"
public foreign handler MCEngineExecExecuteScript(in pScript as String) returns any binds to "<builtin>"
public foreign handler MCEngineExecLog(in pMessage as optional any) returns nothing binds to "<builtin>"
public foreign handler MCEngineExecLogWithValues(in pFormat as String, in pValues as List) returns nothing binds to "<builtin>"
/*
Summary: Resolves a string to a script object.
Object: The string describing the script object.
The result: The resolved script object.
Example:
variable tObject as ScriptObject
resolve script object "button 1 of card 1 of this stack"
put the result into tObject
if tObject exists then
get property "name" of tObject
log the result
else
log "No such button"
end if
Description:
Use the <ResolveScriptObject|resolve script object> statement to obtain a <ScriptObject> in LiveCode Builder, in order to interact with it.
>*Note:* An error is thrown if this syntax is used in a context where access
to script objects is not allowed.
*/
syntax ResolveScriptObject is statement
"resolve" "script" "object" <Object: Expression>
begin
MCEngineExecResolveScriptObject(Object)
end syntax
/*
Summary: Tests the existence of a script object.
Object: An expression that evaluates to a <ScriptObject>.
The result: True if the object <Object> exists, and false otherwise.
Example:
variable tObject as ScriptObject
resolve script object "card 5 of this stack"
put the result into tObject
if tObject exists then
set property "name" of tObject to "Card5"
else
log "No such card"
end if
Description:
Use to test the existence or otherwise of a script object, for example after attempting to resolve the object from a string using <ResolveScriptObject | resolve script object>
References: ResolveScriptObject(statement)
*/
syntax ScriptObjectExists is postfix operator with precedence 3
<Object: Expression> "exists"
begin
MCEngineEvalScriptObjectExists(Object, output)
end syntax
/*
Summary: Tests the existence of a script object.
Object: An expression that evaluates to a <ScriptObject>.
The result: True if the object <Object> exists, and false otherwise.
Example:
variable tObject as ScriptObject
resolve script object "card 5 of this stack"
put the result into tObject
if tObject does not exist then
log "No such card"
end if
Description:
Use to test the non-existence or otherwise of a script object, for example after attempting to resolve the object from a string using <ResolveScriptObject|resolve script object>
References: ResolveScriptObject(statement)
*/
syntax ScriptObjectDoesNotExist is postfix operator with precedence 3
<Object: Expression> "does" "not" "exist"
begin
MCEngineEvalScriptObjectDoesNotExists(Object, output)
end syntax
/*
Summary: Get a property of a script object.
Property: The name of the property to set.
Object: An expression that evaluates to a <ScriptObject>.
The result: The value of the property.
Example:
public handler myScript() as String
get property "script" of my script object
return the result
end handler
Description:
Use to fetch properties of a script object.
>*Note:* An error is thrown if the script object does not exist.
>*Note:* An error is thrown if this syntax is used in a context where access
to script objects is not allowed.
*/
syntax GetPropertyOfScriptObject is statement
"get" "property" <Property: Expression> "of" <Object: Expression>
begin
MCEngineExecGetPropertyOfScriptObject(Property, Object)
end syntax
/*
Summary: Set a property of a script object.
Property: The name of the property to set.
Object: An expression that evaluates to a <ScriptObject>.
Value: The value to set the property to.
Example:
public handler OnMouseUp() returns nothing
set property "name" of my script object to "Clicked Widget"
end handler
Example:
resolve script object "this stack"
set property "invisible" of the result to true
Description:
Use to set properties of a script object.
>*Note:* An error is thrown if the script object does not exist.
>*Note:* An error is thrown if this syntax is used in a context where access
to script objects is not allowed.
*/
syntax SetPropertyOfScriptObject is statement
"set" "property" <Property: Expression> "of" <Object: Expression> "to" <Value: Expression>
begin
MCEngineExecSetPropertyOfScriptObject(Property, Object, Value)
end syntax
/*
Summary: Get the parent object of a script object.
Object: An expression that evaluates to a <ScriptObject>.
The result: The <ScriptObject> that is the owner of <Object>.
Example:
public handler MyName() as String
get property "short name" of my script object
return the result
end handler
public handler OnMouseUp() returns nothing
// Send a message to the widget's parent so it can handle the click
dispatch "widgetClicked" to the owner of my script object with [ MyName() ]
end handler
Description:
Use to get the script object that contains a script object.
>*Note:* An error is thrown if the script object does not exist.
*/
syntax OwnerOfScriptObject is prefix operator with precedence 4
"the" "owner" "of" <Object: Expression>
begin
MCEngineEvalOwnerOfScriptObject(Object, output)
end syntax
/*
Summary: Get the child objects of a script object.
Object: An expression that evaluates to a <ScriptObject>
The result: A list of <ScriptObject>s that are contained within <Object>.
Example:
public handler GetSiblings(in pObject as ScriptObject) as List
// Return the sibling objects of an object
return the children of the owner of pObject
end handler
Example:
// Unset the highlight of all the controls in a group
resolve script object "group \qcheckboxes\q of this card"
variable tObject
repeat for each element tObject in the children of the result
set property "hilite" of tObject to false
end repeat
Description:
Use to get the script objects contained within a script object.
>*Note:* An error is thrown if the script object does not exist.
*/
syntax ChildrenOfScriptObject is prefix operator with precedence 4
"the" "children" "of" <Object: Expression>
begin
MCEngineEvalChildrenOfScriptObject(Object, output)
end syntax
/*
Summary: Send a message to a script object.
Message: The message to dispatch.
Object: The script object to dispatch the message to.
Arguments: A list of arguments for the message.
The result: The result of the message dispatch
Example:
public handler OnMouseUp() returns nothing
// Send a message to the script so it can handle it.
send "buttonClicked" to my script object
end handler
Example:
// myScriptFunction takes three arguments and performs some kind of calculation
variable tObject as ScriptObject
resolve script object "this stack"
put the result into tObject
send function "myScriptFunction" to tObject with [ 2, 3, 4 ]
// the result contains the return value of 'myScriptFunction'
Description:
Sends a message to the given script object and waits for it to finish so that it
can return a value.
After a send, 'the message was handled' predicate can be used to determine if the
message passed through the message path untouched.
>*Note:* An error is thrown if this syntax is used in a context where access
to script objects is not allowed.
*/
syntax SendToScriptObject is statement
"send" ( "function" <IsFunction=true> | "command" <IsFunction=false> | <IsFunction=false> ) <Message: Expression> "to" <Object: Expression> [ "with" <Arguments: Expression> ]
begin
MCEngineExecSendToScriptObject(IsFunction, Message, Object)
MCEngineExecSendToScriptObjectWithArguments(IsFunction, Message, Object, Arguments)
end syntax
/*
Summary: Post a message to a script object.
Message: The message to dispatch.
Object: The script object to dispatch the message to.
Arguments: A list of arguments for the message.
Example:
public handler OnMouseUp() returns nothing
// Send a message to the script so it can handle it.
post "buttonClicked" to my script object
end handler
Description:
Post a message to the given script object and returns immediately. Posting a message
will cause the message to be sent at the next wait point (usually when the current
event has finished being handled).
*/
syntax PostToScriptObject is statement
"post" <Message: Expression> "to" <Object: Expression> [ "with" <Arguments: Expression> ]
begin
MCEngineExecPostToScriptObject(Message, Object)
MCEngineExecPostToScriptObjectWithArguments(Message, Object, Arguments)
end syntax
/*
Summary: Determines whether a message was handled
Example:
public handler OnMouseUp() returns nothing
dispatch "buttonClicked" to my script object
if the message was handled then
return
end if
log "The message was not handled"
end handler
Description:
Determines if a dispatched message was handled by any script objects in the message path.
*/
syntax MessageWasHandled is expression
"the" "message" "was" "handled"
begin
MCEngineEvalMessageWasHandled(output)
end syntax
/*
Summary: Determines whether a message was handled
Example:
public handler OnMouseUp() returns nothing
dispatch "buttonClicked" to my script object
if the message was not handled then
log "The message was not handled"
end if
end handler
Description:
Determines if a dispatched message was handled by any script objects in the message path.
*/
syntax MessageWasNotHandled is expression
"the" "message" "was" "not" "handled"
begin
MCEngineEvalMessageWasNotHandled(output)
end syntax
/*
Summary: Executes some LiveCode script.
Script: The script to execute.
Example:
public handler SnapshotMe() returns nothing
variable tVar as String
get property "number" of my script object
put the result formatted as string into tVar
// Create a snapshot from the rect of the widget
execute script "import snapshot from rect (the rect of widget " & tVar & ") of widget " & tVar
end handler
Description:
Executes the given piece of LiveCode script in the context of the current script
object.
>*Note:* An error is thrown if this syntax is used in a context where access
to script objects is not allowed.
*/
syntax ExecuteScript is statement
"execute" "script" <Script: Expression>
begin
MCEngineExecExecuteScript(Script)
end syntax
/*
Summary: Logs a string.
String: The string to log.
Arguments: A list of arguments.
Example:
variable tList as List
get property "name" of my script object
push the result onto tList
get property "id" of my script object
push the result onto tList
log "Widget %@ has id %@" with tList
Description:
The log command triggers a logChanged message with the accumulated log messages since the logChanged message was last handled.
This can be handled in LiveCode Script, for example:
```
on logChanged pLog
write pLog to stdout
end logChanged
```
*/
syntax Log is statement
"log" <Message: Expression> [ "with" <Arguments: Expression> ]
begin
MCEngineExecLog(Message)
MCEngineExecLogWithValues(Message, Arguments)
end syntax
end module