webCOMAND

cScript Expressions

cScript code is made up of expressions, separated by semicolons.  An expression can be a variable assignment, function call or combination of the two.  It may include text, math, logic and functions to produce the ultimate outcome.  The following are supported in cScript expressions.

Constants

Keyword Meaning
true Boolean TRUE
false Boolean FALSE
null NULL
undefined Not set or invalid result (divide by zero)

Text

Text is represented by a single or double-quoted string of characters.

echo("This is a string of double-quoted text.");
echo('This is a string of single-quoted text.');

Escape Sequences

Certain characters, such as the surrounding quote character, new lines, tabs are preceded by a backslash.

echo("This is a string with \"quoted text\" and a trailing new line.\n");

UTF8 character codes are also preceded by a backslash to specify any UTF8 character.

echo("This is a utf8 character: \u263a");

Appending Strings

Multiple strings and variables can be appended together with the plus sign (+).

echo("Hello" + ' World.');

Variables

$a = ${b.Field};
$a = $b.Field;  // {} notation not required

Arrays and Collections

$array2 = [];
$array3 = [1, 2, 3];
$array3 []= 4;

Associative Arrays

$array2 = [];
$array3 = ['a': 1, 'b': 2, 'c': 3];
$array3['a'] = 1;
$array3['b'] = 2;
$array3['c'] = 3;

Objects

Simple free-form objects can be created with arbitrary properties by initializing a variable with {}.

cScript does not currently support property initialization within the {}, but it may be added in the future.

It is also possible to define classes and instantiate instances of that class with Custom Classes.

$object = {};
$object.property = 'value';

Assignment

Operator Description
= Equal
+= Add (numbers) or append (string)

Comparison Operators

Operator Description
== or eq Equal
!= or ne Not Equal
=== Exactly Equal (same type and value)
!== Not Exactly Equal (same type and value)
<=> Sort comparison: -1, 0 or 1
< or lt Less than
> or gt Greater than
<= or le Less than or Equal
>= or ge Greater than or Equal

Logic

Operator Description
|| Logical OR
&& Logical AND

Math

Operator Description
+, -, *, /, % Add, Subtract, Multiply, Divide, Modulo (divide and return remainder)
++ Increment
-- Decrement
=~ Regular expression match or substitution, formatted like Perl, except uses PHP's preg_match() and preg_replace() internally.

Ternary Operator (?:)

Provides a shorthand if/else.

$y = ($x == 5 ? 5 : 0);

Undefined Coalescing Operator (??)

Provides a shorthand if($x !== UNDEFINED){ $y = $x } else { $y = 'default' }.  This is the same as the Null Coalescing Operator in PHP.

$y = ($x ?? 'default');

Functions

cScript Functions can appear in an expression anywhere a value can.  The return value of the function will be used.

Example

$array = [1, 2, 3];
if(count($array) < 3) {
    echo("There are less than 3 items.");
} elseif(count($array) >= 3) {
    echo("There are 3 or more items.");
}