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.
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.
Statements are formed by combining one or more of the following:
ChaiScript supports both ints and doubles.
Example int:
10Example doubles:
3.14, NaN, Infinity
Example booleans:
true, false
Any variable identifier that follows the C naming convention.
Example variable:
bob
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}"
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 |
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.
Example expression:
3 + 4 * 5
Mathematical expression following the order of precedence mentioned in "Operators".
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.
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 Call ::= fun_name "(" [arg ("," arg)*] ")"
Calls the function pointed to by the lhs value.
Method Call ::= obj_name "." fun_name "(" [arg ("," arg)*] ")"
In ChaiScript the above notation is identical to:
fun_name "(" obj_name ("," arg)* ")"
Array Call ::= obj_name "[" key "]"
An array value lookup. In maps, 'key' is a string value, in vectors it is a numeric index.
Throw ::= "throw" "(" value ")"