Quirrel4.41.0

The language

This chapter describes the language: what the compiler accepts, and what each construct does at runtime. The standard library is not here. Each function has its own page under Modules and Types.

Quirrel is a C-family language with dynamic types, closures, generators, classes and reference-counted memory. If you already write Python, JavaScript, Lua or Squirrel, start at the introduction. It maps what you know onto these pages, so you can read only the parts that differ.

The pages are in reading order. Each one is short, states the rule, and shows a sample that runs.

Pages

Lexical structureComments, identifiers, keywords, number literals and statement separators.
Bindings and constantslocal, let, const and enum, and the scope of each one.
Values and typesThe fourteen value types, truthiness, number precision, and equality.
FunctionsDefinitions, default and vararg parameters, calls and closures.
Operators and expressionsOperator precedence, values that count as false, and the null-safe operators.
Control flowif, while, for, foreach, and switch (off by default).
Tables and arraysTables and arrays: slots, order, growth and freezing.
StringsOrdinary, verbatim and interpolated string literals; strings are immutable bytes.
Classes and instancesClass bodies, instances, inheritance and static members.
MetamethodsThe seventeen reserved method names the VM calls, and the contract of each.
DestructuringPatterns that bind a table's keys or an array's positions to names.
Generators and threadsyield, resume, generator states, and the differences from threads.
async and awaitasync functions, await, and the Future an async call returns.
Modulesrequire, from-import, module exports, persist and reloading.
Type annotationsType annotations on a parameter, a return type or a binding.
Errors and exceptionsthrow, try/catch, assert, and uncaught errors.
Compiler directivesThe # directives that turn a language feature on or off.

The shape of the language

See also