Project

General

Profile

6.5. XILab scripts

XILab scripting language is implemented using QtScript, which in turn is based on ECMAScript.
ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262.
QtScript (and, by extension, XILab) uses third edition of the ECMAScript standard.

Brief description of the language

Data Types

ECMAScript supports nine primitive data types. Values of type Reference, List, and Completion are used only as intermediate results of expression evaluation and cannot be stored as properties of objects. The rest of the types are:
  • Undefined,
  • Null,
  • Boolean,
  • String,
  • Number,
  • Object.

Statements

Most common ECMAScript language statements are summarized below:

Name Usage Description
Block {[<statement list>]} Several statements may be grouped into a block using braces.
Variable declaration var <varialble declaration list> Variables are declared using "var" keyword.
Empty statement ; Semicolon denotes an empty instruction. It is not required to end a line with a semicolon.
Conditional execution if (<condition>) <instruction>
[ else <instruction> ]
Conditional execution is done using "if ... else" keywords. If a condition is true, then "if"-block instruction is executed, else an "else"-block instruction is executed.
Loop do <loop body> while (<condition>)
while (<condition>) <loop body>
for ([<initialization>]; [<condition>]; [<iterative statement>]) <loop body>
Loops have several forms. A "do ... while ..." loop executes loop body and then checks if condition is true or false to see whether it should stop or continue running. A "while ... do ..." loop repeatedly checks the condition and executes loop body if it is true. A "for ..." loop executes an initialization statement once, then executes an iterative statement and loop body while the condition is true.
Return return [<expression>] Stops function execution and returns expression as a result.
Exception throw <expression> Generates or "throws" an exception, which may be processed by the "try" statement (see below).
Try-catch block try <block> catch  (<identifier>) <block>
try <block> finally <block>
try <block> catch (<identifier>) <block> finally <block>
Used together with exceptions. This statement tries to execute its "try"-block. If an exception is thrown in it, then a "catch"-block is executed. Finally a "finally"-block is executed unconditionally. Either a "catch" or a "finally" block may be omitted.

Variable statements

Variables are declared using var keyword. A declared variable is placed within visibility scope that corresponds to the function in which it is declared. If the variable is declared outside of functions, it is placed in the global visibility scope. Variable is created when the function within which it was declared, or, if the variable is global, at the start of the application. When a variable is created it is initialized with Undefined value. If a variable is created with initialization, the initialization does not occur in the moment of variable creation, it happens when the string with the var statement executes.

Reserved words

The following words are the reserved keywords in the language and may not be used as identifiers:

break     else        new     var
case      finally     return  void
catch     for         switch  while
continue  function    this    with
default   if          throw
delete    in          try
do        instanceof  typeof

The following words are used as keywords in proposed extensions and are therefore reserved to allow
for the possibility of future adoption of those extensions:

abstract  enum        int        short
boolean   export      interface  static
byte      extends     long       super
char      final       native     synchronized
class     float       package    throws
const     goto        private