Table Of Contents
The script engine is a very powerful parsing facility that can parse, bind and execute source code similar to ANSI-C and Objective-C. It implements the usual ANSI-C functions and operators as well as syntax construction and binding to permit reference and execution of a function or method that can be looked up by the runtime system.
Because of the broad nature of the script engine only the most relevant features are described in this section. For additional information consult a reference on ANSI-C or Objective-C.
Functions
- The common functions are implemented such as: abs, acos, asin, atan, atan2, ceil, cos, cosh, div, exp, fabs, floor, fmod, frexp, labs, ldexp, ldiv, log, log10, modf, pow, rand, sin, sinh, sqrt, srand, tan, tanh. These functions are pre-declared for the Formula Selector principally because a formula is a single-statement program and as such can not accept a declaration statement.
- Theoretically, any function available to the binary can be accessed but you do need to specify the function declaration. For example the following declares the cosine function. Make sure to use the exact type needed, in this case a double type, when passing the argument. Without a specific declaration a function can not be accessed so it is important to declare functions in advance of the execution block.
- Scripting is not really a substitute for a large computation. Because of that you may want to consider implementing any large scale computation into a Plugin.
Operators
- The common operators are implemented such as: !, !=, %, %=, &&, &=, +, ++, +=, -, --, -=, /, <, >, <<, <<=, <=, =, ==, >, >=, >>, >>=. These operators are implicitly defined and do not have to be declared. They are all available within a single statement and as such can be used as a formula within the Formula Selector.
Expressions
The common expressions are implemented such as:
Blocks
- The common blocks are implemented such as: () and {}. Note that the executable portion of a script (not the declaration) needs to be enclosed in a {} block. That is because the upper-most scope blocks are the entrance point to execution as well as scoping of variables.
- Both block types can be used in the Formula Selector formula statement, however the algebraic () block is the one that makes most sense.
Methods
- Methods are written like
@@method(public, instance)myMethod:(int)anArg
and @@method(public, class)myMethod:(int)anArg
and wrapped in a class block like this: @@class() Rectangle:Object ... @@end
.
- The analog in Objective-C is fairly straightforward.
Use
The following script fragment gives an example.
[myFunction emptyData];
for(ii = 0; ii < 500; ii++)
{
xValue = 0.01 * ii + animationCount * 0.5;
yValue = cos(xValue);
[myFunction appendXValue:xValue yValue:yValue];
}
|
That makes a cosine curve (function) in the usual way. For specific scripts see each API code section, for example the Function section.