Squirrel
Squirrel is a programming language similar to Lua, but uses a C like syntax. In Source Squirrel is used as one of the scripting languages in the VScript scripting system. The official Squirrel documentation can be found here
Squirrel heavily uses an associative array data structure called a table. Both the keys and values of a table can contain almost any kind of variable. The scripting environment consists of nested tables, and when a script is executed its variables and functions are added as table slots.
Variables
Squirrel has two kinds of variables; table slots and local variables. Since the execution scope is always a table, any variables declared outside functions will always be table slots. Table slots have to be declared using the <-
operator.
Variables local to functions can be declared using the <-
keyword.
Global variables are simply slots in the root table, and can be declared using the ::
scoping operator.
here is an example illustrating the declaration and use of variables.
// Variable declaration.
a <- 5
b <- "A text string"
// Modifying the variable.
b = "New string"
function MultiplyWithTwo(inValue)
{
// Local variable declaration.
local factor = 2
return inValue * factor
}
// Global variable declaration. Sets x to 10.
::x <- MultiplyWithTwo(a)
Data Types
[Todo]
Data Structures
Squirrel has built-in support for two different data structures, arrays and tables.
Arrays
Arrays are sequences of objects that are numerically indexed starting from 0. Syntactically they function similarly to C arrays, but unlike C arrays, they are mutable and values can be inserted and removed using a set of built in functions.
Arrays are defined using square brackets.
// Array definition.
myArray <-
[
7,
"more text",
null,
1
]
// Prints "7"
printl(myArray[0])
myArray.remove(0)
// Prints "more text"
printl(myArray[0])
Tables
Tables are defined using curly brackets.
[Todo]
Functions
[Todo]
Classes
[Todo]
Scripting
[Todo]
See Also
External links
- Squirrel (programming language) - Wikipedia Article on Squirrel
- Squirrel Official Website
- Squirrel Binary for Windows