Sample Page

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.[2] It is used extensively by Code::Blocks for scripting and was also used in Final Fantasy Crystal Chronicles: My Life as a King.[3][4] 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.[5]

Language features

Development state

Version 2.0 was released in April 3, 2005.

The current Stable release is 3.2 in February 10, 2022.[6]

The project has been designed to compile and run on Windows (86x, 64x), Linux, Illumos (both x86 & x64), and Android And, IOS, Mac Os And FreeBSD.[7]

Has been tested with The Following Compilers:

  • MS Visual C++ 6.0,7.0,7.1,8.0,9.0 and 10.0(x86 & 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.[8]

Integer:

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

local a = 123 //decimal
local b = 0x0012 //hexadecimal
local c = 075 //octal [10]

Float:

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

local a=1.0 local b=0.234

String:

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

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:

local a = "I'm a wonderful string\n"
// has a newline at the end of the string
local x = @"I'm a verbatim string\n"
// the \n is literal, similar to "\\n" in a regular string.

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

local multiline = @"
    this is a multiline string
    it will ""embed"" all the new line
    characters 

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.:

local a = 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).:[12]

local a = true;

Table

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

local t={}
local test=
{
    a=10
    b=function(a) { return a+1; }
}

Array

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

local a  = ["I'm","an","array"]
local b = [null]
b[0] = a[2];

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.[14]

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.[15]

Generator

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

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).[12]

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

base break case catch class clone
continue const default delete else enum
extends for foreach function if in
local null resume return switch this
throw try typeof while yield constructor
instanceof true false static __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.[12]

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.[12]

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:[12]

/* any text between will be ignored */

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

34 Integer number(base 10)
0xFF00A120 Integer number(base 16)
0753 Integer number(base 8)
'a' Integer number
1.52 Floating point number
1.e2 Floating point number
1.e-2 Floating 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…[12]

Factorial in Squirrel

local function factorial(x) // Getting function which is factorial, then getting value which is x
{
  if (x <= 1) {  // if x is less than 1
    return 1;  // then the code will just return 1
  }
  else { // if that doesn't work
    return x * factorial(x-1); // then the code will return x times factorial(x-1)
  }
}

Generators

function not_a_random_number_generator(max) {
  local last = 42;
  local IM = 139968;
  local IA = 3877;
  local IC = 29573;
  for(;;) { // loops forever
    yield (max * (last = (last * IA + IC) % IM) / IM);
  }
}

local randtor = not_a_random_number_generator(100);

for(local i = 0; i < 10; i += 1)
   print(">"+resume randtor+"\n");

Classes and inheritance

class BaseVector {
  constructor(...)
  {
    if(vargv.len() >= 3) {
      x = vargv[0];
      y = vargv[1];
      z = vargv[2];
    }
  }
  x = 0;
  y = 0;
  z = 0;
}

class Vector3 extends BaseVector {
  function _add(other)
  {
    if(other instanceof ::Vector3)
      return ::Vector3(x+other.x,y+other.y,z+other.z);
    else
      throw "wrong parameter";
  }
  function Print()
  {
    ::print(x+","+y+","+z+"\n");
  }
}

local v0 = Vector3(1,2,3)
local v1 = Vector3(11,12,13)
local v2 = v0 + v1;
v2.Print();

Applications

Applications using Squirrel

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

Games using Squirrel

History

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

See also

References

  1. ^ “squirrel/HISTORY at master – albertodemichelis/squirrel – GitHub”.
  2. ^ MirthKit Developer Wiki Archived 2014-02-11 at the Wayback Machine
  3. ^ a b Brandon Boyer (21 February 2008). “Gamasutra – GDC 2008 Event Coverage”. gamasutra.com. Gamasutra. Archived from the original on May 9, 2010.
  4. ^ “Exclusive: Behind The Scenes of Final Fantasy’s WiiWare Debut”. gamasutra.com. Gamasutra. 23 June 2008. Archived from the original on November 10, 2010. Retrieved 22 September 2011.
  5. ^ “L4D2 Vscripts – Valve Developer Community”. developer.valvesoftware.com. Retrieved 2018-07-06.
  6. ^ a b “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  7. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  8. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  9. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  10. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  11. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  12. ^ a b c d e f g “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  13. ^ a b “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  14. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  15. ^ “Squirrel – The Programming Language”. squirrel-lang.org. Retrieved 2026-06-08.
  16. ^ “Electric Imp programming guide”. electricimp.com.
  17. ^ a b c d e f g “VScript”. valvesoftware.com. 2014-08-20. Retrieved 2015-01-17.
  18. ^ “th155-decomp”. GitHub. Retrieved 2020-10-19.
  19. ^ Gothic 2 Online
  20. ^ “iv-multiplayer.com”. www.iv-multiplayer.com. Archived from the original on 2012-06-07. Retrieved 2018-07-06.
  21. ^ “Liberty Unleashed”. Retrieved 2019-12-04.
  22. ^ “m2-multiplayer.com”. www.m2-multiplayer.com. Archived from the original on 2013-01-02. Retrieved 2018-07-06.
  23. ^ “undernightinbirth”. GitHub. Retrieved 2024-08-18.
  24. ^ “AI:Main Page – OpenTTD”. wiki.openttd.org. Retrieved 2018-07-06.
  25. ^ “Heated Metal”. Github. Retrieved 2026-01-09.
  26. ^ “Simutrans-Squirrel-API: Main Page”. dwachs.github.io. Retrieved 2018-07-06.
  27. ^ “The VG Resource Wiki”. wiki.vg-resource.com. Retrieved 2021-09-04.
  28. ^ “Team Fortress 2 Update Released”. Retrieved 2026-01-17.
  29. ^ “Thimbleweed Park Blog- Engine”. blog.thimbleweedpark.com. Retrieved 2018-07-06.
  30. ^ “NewDark 1.25: Squirrel script?”. ttlg.com. 2017-03-20. Retrieved 2019-12-25.
  31. ^ Vice City Multiplayer
  32. ^ “Welcome To VC-MP website!”. Archived from the original on 2006-04-05. Retrieved 2014-05-04.
  33. ^ “undernightinbirth”. GitHub. Retrieved 2024-08-18.
  34. ^ “The Squirrel programming language”. SourceForge. Retrieved 2018-07-06.
  35. ^ “Moving to code.google.com and MIT License – The Language – Squirrel – The Programming Language”. forum.squirrel-lang.org. Retrieved 2018-07-06.
  36. ^ “Google Code Archive – Long-term storage for Google Code Project Hosting”. code.google.com. Retrieved 2018-07-06.