Squirrel is a high level imperative, object-oriented programming language, designed to be a lightweight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games, released in September 6, 2003.

MirthKit, a simple toolkit for making and distributing open source, cross-platform 2D games, uses Squirrel for its platform. It is used extensively by Code::Blocks for scripting and was also used in Final Fantasy Crystal Chronicles: My Life as a King. It is also used in Left 4 Dead 2, Portal 2, Team Fortress 2, Thimbleweed Park, and War Thunder for scripted events and in NewDark, an unofficial Thief 2: The Metal Age engine update, to facilitate additional, simplified means of scripting mission events, aside of the regular C scripting.

Language features

Development state

Version 2.0 was released on April 3, 2005. The current stable release is 3.2, released on February 10, 2022.

The project can compile and run on Windows (x86 and x64), Linux, Illumos (x86 and x64), Android, iOS, macOS, and FreeBSD.

It has been tested with the following compilers:

  • Microsoft Visual C++ 6.0, 7.0, 7.1, 8.0, 9.0, and 10.0 (x86 and x64)
  • MinGW gcc 3.2 (mingw special 20020817-1)
  • Cygwin gcc 3.2
  • Linux gcc 3.x
  • Linux gcc
  • xIllumos
  • xXCode 4

Values and Data types, Lexical Structure

While Squirrel is a dynamically typed language and variables do not have a type, different operations may interpret the variable as containing a type. Squirrel’s basic types are integer, float, string, null, table, array, function, generator, class, instance, bool, thread and userdata.

Integer:

An Integer represents a 32 bit (or better) signed number.:

Float:

A float represents a 32 bit (or better) floating point number.:

String:

strings are an immutable sequence of characters. In order to modify a string is it necessary create a new one.

Squirrel’s strings are similar to strings in C or C++. They are delimited by quotation marks(") and can contain escape sequences (\t, \a, \b, \n, \r, \v, \f, \\, \", \', \0, \x<hh>, \u<hhhh> and \U<hhhhhhhh>).

Verbatim string literals do not interpret escape sequences. They begin with @" and end with the matching quote. Verbatim string literals also can extend over a line break. If they do, they include any white space characters between the quotes:

However, a doubled quotation mark within a verbatim string is replaced by a single quotation mark:

Null:

The null value is a primitive value that represents the null, empty, or non-existent reference. The type Null has exactly one value, called null.:

Bool

Bool is a double-valued (Boolean) data type. Its literals are true and false. A bool value expresses the validity of a condition (tells whether the condition is true or false).:

Table

Tables are associative containers implemented as a set of key/value pairs called slots.:

Array

Arrays are simple sequence of objects. Their size is dynamic and their index always starts from 0.:

Function

Functions are similar to those in other C-like languages with a few key differences (see below).

Class

Classes are associative containers implemented as sets of key/value pairs. Classes are created through a ‘class expression’ or a ‘class statement’. class members can be inherited from another class object at creation time. After creation, members can be added until an instance of the class is created.

Class Instance

Class instances are created by calling a class object. Instances, as tables, are implemented as sets of key/value pairs. Instance members cannot be dynamically added or removed; however the value of the members can be changed.

Generator

Generators are functions that can be suspended with the statement ‘yield’ and resumed later (see Generators).

Userdata

Userdata objects are blobs of memory or pointers defined by the host application but stored within Squirrel variables (See Userdata and UserPointers).

Thread

Threads are objects representing a cooperative thread of execution, also known as coroutines.

Weak Reference

Weak References are objects that point to another (non-scalar) object but do not own a strong reference to it. (See Weak References).

The following words are reserved and cannot be used as identifiers:

basebreakcasecatchclassclone
continueconstdefaultdeleteelseenum
extendsforforeachfunctionifin
localnullresumereturnswitchthis
throwtrytypeofwhileyieldconstructor
instanceoftruefalsestatic__LINE____FILE__
rawcall

Identifiers start with an alphabetic character or the symbol ‘_’ followed by any number of alphabetic characters, ‘_’ or digits ([0-9]). Squirrel is a case sensitive language meaning that the lowercase and uppercase representation of the same alphabetic character are considered different characters. For instance, “foo”, “Foo” and “fOo” are treated as 3 distinct identifiers.

Squirrel recognizes the following operators:

!!=||==&&>=<=>
<=>++=--=//=*
*=%%=++--<-=&
^|~>><<>>>

As for Significant tokens:

{}[].:
::';"@"

A comment is text that the compiler ignores but that is useful for programmers. Comments are normally used to embed annotations in the code. The compiler treats them as white space.

A comment can be /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the */ characters. This syntax is the same as ANSI C:

/* any text between will be ignored */

Squirrel accepts integer numbers, floating point numbers and string literals.

34Integer number(base 10)
0xFF00A120Integer number(base 16)
0753Integer number(base 8)
'a'Integer number
1.52Floating point number
1.e2Floating point number
1.e-2Floating point number
"I'm a string"String
@"I'm a verbatim string"String
@" I'm a multiline verbatim string "String

Syntax

squirrel's syntax is similar to C/C++/Java etc... but the language has a very dynamic nature like Python/Lua etc...

Factorial in Squirrel

Generators

Classes and inheritance

Applications

Applications using Squirrel

  • Code::Blocks, integrated development environment
  • Enduro/X, cluster application server
  • Electric Imp, an end-to-end IoT platform

Games using Squirrel

History

The language was made public in 2003 under the zlib/libpng license. In November 2010, the license was changed to the MIT license to enable the project to be hosted on Google Code. It is developed and maintained by Alberto Demichelis.

See also

External links