About ChaiScript

ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility in mind. It is an ECMAScript-inspired, embedded functional-like language.

ChaiScript is licensed under the BSD license.

Download

Version: 2.3.3 Released: 5/15/2010

Source
Windows
Linux

Statement Types

Statements are formed by combining one or more of the following:

Numbers

ChaiScript supports both ints and doubles.

Example int:

10

Example doubles:

3.14, NaN, Infinity

Booleans

Example booleans:

true, false

Variables

Any variable identifier that follows the C naming convention.

Example variable:

bob

Strings

Quoted string values.

Example string:

"test me"

Strings accept the following escaped sequences:

Sequence Description
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Tab
\' Single quote
\" Double quote
\\ Single backslash

Strings also allow in-string evaluation, which allows you to evaluate simple expressions inside of the string. For example:

var five = 5
"3 + 5 = ${3 + five}"

Characters

Single-Quoted char values.

Example char:

'b'

Chars also accept the following escaped sequences:

Sequence Description
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Tab
\' Single quote
\" Double quote
\\ Single backslash

Operator Literals

A special form of the operator that allows you to reference it as an identifier.

Example operator literal:

`+`

Note: These may be used as first-class functions.

Expressions

Example expression:

3 + 4 * 5

Mathematical expression following the order of precedence mentioned in "Operators".

Variable Declarations

Variable Declaration ::= "var" identifier

A variable name preceded by the keyword var, which declares the variable as an anonymous type. Once a variable has been given a type by assigning it to a value, the variable must maintain this type while it's in scope.

Equations

Equation ::= lvalue "=" rvalue

Takes a copy of what is on the right hand side and assigns it to the identifier named on the left hand side. For complex types this calls the "clone" method for that type.

Function Calls

Function Call ::= fun_name "(" [arg ("," arg)*] ")"

Calls the function pointed to by the lhs value.

Method Calls

Method Call ::= obj_name "." fun_name "(" [arg ("," arg)*] ")"

In ChaiScript the above notation is identical to:

fun_name "(" obj_name ("," arg)* ")"

Array Calls

Array Call ::= obj_name "[" key "]"

An array value lookup. In maps, 'key' is a string value, in vectors it is a numeric index.

Throwing Exceptions

Throw ::= "throw" "(" value ")"