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.');

UTF8

cScript text may contain UTF8 characters and can be safely manipulated with the various string functions, such as strtoupper().

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 can also be preceded by a backslash to specify any UTF8 character.

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

Appending Text

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

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

Variables

$a = "This is a string.";
echo($a);

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

Strings

Single and double-quoted text strings can contain variables.

$a = "World";
echo("Hello $a.");

Individual characters within a text string can be accessed by their index, similar to an array element.

The string index is a character index, not a byte index, so all UTF8 characters count as a single character.  This is different than PHP and some other languages.
// this will echo the letter 's'
$a = "This is a string.";
echo("The fourth character in the text string is: " + $a[3]);

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)
-= Subtract
*= Multiply
/= Divide
%= Modulo

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
=~ Regular expression match or substitution, formatted like Perl, except uses PHP's preg_match() and preg_replace() internally.  See cScript Regular Expressions.

Logic

Operator Description
|| Logical OR
&& Logical AND

Math

Operator Description
+, -, *, /, % Add, Subtract, Multiply, Divide, Modulo (divide and return remainder)
++ Increment
-- Decrement

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.");
}