ChaiScript
ChaiScript Language Keyword Reference

attr

Defines a ChaiScript object attribute

Attribute Definition ::= "attr" class_name "::" attribute_name
See also
ChaiScript Language Object Model Reference

auto

Defines a variable

Variable ::= "auto" identifier

Synonym for var


break

Stops execution of a looping block.

Break Statement ::= "break"
See also
for
while

def

Begins a function or method definition

Function Definition ::= "def" identifier "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block
Method Definition ::= "def" class_name "::" method_name "(" [[type] arg ("," [type] arg)*] ")" [":" guard] block

identifier: name of function. Required. args: comma-delimited list of parameter names with optional type specifiers. Optional. guards: guarding statement that act as a prerequisite for the function. Optional. { }: scoped block as function body. Required.

Functions return values in one of two ways:

By using an explicit return call, optionally passing the value to be returned. By implicitly returning the value of the last expression (if it is not a while or for loop).

Method definitions for known types extend those types with new methods. This includes C++ and ChaiScript defined types. Method definitions for unknown types implicitly define the named type.

See also
ChaiScript Language Object Model Reference

else

See also
if

for

For Block ::= "for" "(" [initial] ";" stop_condition ";" loop_expression ")" block

This loop can be broken using the break command.


fun

Begins an anonymous function declaration (sometimes called a lambda).

Lambda ::= "fun" "(" [variable] ("," variable)* ")" block

Example

// Generate an anonymous function object that adds 2 to its parameter
var f = fun(x) { x + 2; }
See also
def for more details on ChaiScript functions

if

Begins a conditional block of code that only executes if the condition evaluates as true.

If Block ::= "if" "(" condition ")" block
Else If Block ::= "else if" "(" condition ")" block
Else Block ::= "else" block

Example

if (true) {
// do something
} else if (false) {
// do something else
} else {
// otherwise do this
}

try

Try Block ::= "try" block
("catch" ["(" [type] variable ")"] [":" guards] block)+
["finally" block]
See also
ChaiScript_Language::throw

while

Begins a conditional block of code that loops 0 or more times, as long as the condition is true

While Block ::= "while" "(" condition ")" block

This loop can be broken using the break command.


var

Defines a variable

Variable ::= "var" identifier

Synonym for auto