• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Sequencer
  • Sequencer - ChaiScript

Sequencer - ChaiScript

Expression Syntax

The Chai script expressions make use of ChaiScript parser to parse and evaluate ChaiScript code.

ChaiScript is a strongly typed declarative language with syntax similar to C++. Important differences from C++ are: Flow-of-control constructs like if, for and while use code enclosed in { … }; they cannot take single statements. There are no post-increment or post-decrement operators (++ and -- after the variable name).

Expressions can take many forms - the last expression result is returned as the boolean value. MyArg1 > MyArg2

It is possible to add debug prints in the expressions. print(Count); Count>5

When comparing non-boolean values with boolean comparisons the values need to be cast to boolean. bool(Count1) || bool(Count2)

Loops and Conditionals require brackets for the code block. if (expression) { print("expression is true"); }

Conditional expressions must have bool type result, that may requre casting of values to bool. if (bool(ArgumentOut)) { print("Good"); }

The expression does not support variable declarations due to performance reasons. The expression is parsed once and then reevaluated each time needed. This makes declaring local variables in the expression not possible as they would be declared anew each time and cause a symbol redeclaration error.

Note: For operators expecting a boolean argument, use bool(MyInt) to construct a boolean value out of other primitive types.

Note: Note that as variable in ChaiScript can not contain spaces all CDP node names that contain spaces in the name must be referred with spaces removed from the name (like 'My Argument' should be referred as 'MyArgument' in ChaiScript).

Mathematical operators supported by ChaiScript

OperatorDescriptionPriority
?:ternary operator; expects a boolean argument, other values can be used via explicit cast: bool(MyInt) ? true:false1
||logical or; expects boolean arguments, other values can be used via explicit cast: bool(MyInt1) || bool(MyInt2)2
&&logical and; expects boolean arguments, other values can be used via explicit cast: bool(MyInt1) && bool(MyInt2)3
|bitwise or4
^bitwise xor5
&bitwise and6
!=not equal7
==equal7
<=less or equal8
>=greater or equal8
<less than8
>greater than8
<<shift left9
>>shift right9
+addition10
-subtraction10
*multiplication11
/division11
%modulo11
++prefix increase value12
--prefix decrease value12
-prefix minus sign12
+prefix plus sign12
!prefix invert; expects a boolean argument, other values can be used via explicit cast: !bool(MyInt1)12
~prefix bitwise invert12

Note: Lines in multi-line ChaiScript are not allowed to start with an Operator

Note: For functions expecting a float or double type argument use double() constructor like pow(double(MyInt), 2.0); to call with integer numbers.

Mathematical functions supported by ChaiScript for double and float types

Function# of argumentsExplanation
sin1sine function
cos1cosine function
tan1tangent function
asin1arcus sine function
acos1arcus cosine function
atan1arcus tangens function
sinh1hyperbolic sine function
cosh1hyperbolic cosine
tanh1hyperbolic tangent function
asinh1hyperbolic arcus sine function
acosh1hyperbolic arcus tangent function
atanh1hyperbolic arcus tangent function
log21logarithm to the base 2
log101logarithm to the base 10
log1logarithm to base e (2.71828...)
exp1e raised to the power of argument value
exp212 raised to the power of argument value
pow2first argument raised to the power of second
sqrt1square root of a value
hypot2Computes the square root of the sum of the squares of two arguments
sign1sign function -1 if < 0; 1 if > 0
rint1round to nearest integer
fabs1absolute value
fmin2min of arguments
fmax2max of arguments
fdim2Equivalent to fmax(arg1-arg2, 0)
fma3Computes (arg1 * arg2) + arg3 as if to infinite precision and rounded only once to fit the result type
erf1Computes the error function of argument
erfc1Computes the complementary error functionof arg, that is 1.0-erf(argument)
ceil1Computes the smallest integer value not less than the argument
floor1Computes the largest integer value not greater than the argument
fmod2Computes the floating-point remainder of the division operation the <first argument> / the <second argument>
trunc1Computes the nearest integer not greater in magnitude than the argument
round1Computes the nearest integer value to the argument (in floating-point format), rounding halfway cases away from zero
isinf1Determines if the given floating-point number argument is a positive or negative infinity
isnan1Determines if the given floating point number argument is a not-a-number (NaN) value
signbit1Determines if the given floating point number argument is negative.
isnormal1Determines if the given floating point number argument is normal, i.e. is neither zero, subnormal, infinite, nor NaN
isfinite1Determines if the given floating point number argument has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN
isunordered2Returns 1 if either argument is NaN, ​0​ otherwise
_pi0the value of PI (3.141592653589793238462643)
_e0Euler's number (2.718281828459045235360287)

Mathematical functions supported by ChaiScript for number types

Function# of argumentsExplanation
bool1Constructs boolean value out of other primitive types and string; where an empty string is considered false
min2Returns the minimum value of two numbers
max2Returns the maximum value of two numbers
odd1Returns true if the value is odd
even1Returns true if the value is even
abs1Computes the absolute value of an integer argument.

String functions supported by ChaiScript

Function# of argumentsExplanation
find2Returns the position of the second argument string in the first argument string or -1
rfind2Returns the position of the last match of the second argument string in the first argument string or -1
ltrim1Returns left trimmed string of the string argument
rtrim1Returns right trimmed string of the string argument
trim1Returns trimmed string of the string argument
replace3Returns string where in the first argument the occurrences of the second argument are replaced for the third argument
toLowerCase1Returns the string argument in lowercase
toUpperCase1Returns the string argument in upper case

See also EventIn, State, RunOperation, and Operation.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top