Wikipedia / Squirrel (programming language)
Wikipedia / Squirrel (programming language)
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
Cooperative threads (coroutines)
Automatic memory management (mainly reference counting with backup garbage collector)
Both compiler and virtual machine fit together in about 7k lines of C++ code
Optional support for UCS-2 wide strings
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.:
local a = 123 //decimal
local b = 0x0012 //hexadecimal
local c = 075 //octal Float
A float represents a 32 bit (or better) floating point number.:
local a=1.0 local b=0.234String
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:
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:
local multiline = @"
this is a multiline string
it will ""embed"" all the new line
charactersNull
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 = nullBool
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).:
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.:
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.
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: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.
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===
Gothic Online, a mod for Gothic II
GTA IV IV-MP
Liberty Unleashed
Mafia II M2-Multiplayer
Tom Clancy's Rainbow Six Siege Heated Metal
Sonic Unleashed (PS2/Wii)
Thief II (unofficial NewDark engine update)
Vice City Multiplayer, a mod for Grand Theft Auto: Vice City
Zero no Tsukaima - Maigo no Period to Ikusen no Symphony (PS2)
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
References
External links