Skip to main content

Squirrel Keyword Reference

Reserved Words And Their Meanings

The Squirrel language defines more than 30 keywords. These are reserved names and must not be used for variable identifiers. The list below is intended to be used as a quick look-up reference to these keywords. For a fuller description of their functionality and examples of their use, see the Squirrel Programming Guide.

base

Provides access to the methods and properties of a class’ parent class. Child classes are declared using the extends keyword.

break

Causes the execution of a switch... case, do... while or while... structure to come to an end.

case

Indicates a block of code to be run if the variable tested in a switch... case structure matches the value specified by the case statement.

catch

Part of a try... catch structure, it indicates the code to be run if an exception is raised by the code indicated by try.

class

Indicates the start of a class definition.

clone

A function used to create a duplicate of the passed object. The copy is complete; it is not a collection of references to the methods and properties of the original.

constructor

Indicates a class’ initialization function, called automatically when the class is instantiated.

continue

Causes Squirrel to return to the point after the last break statement it processed.

const

Marks the following identifier as a constant.

default

Marks the default condition in a switch... case structure. The code block that follows is executed if none of the structure’s case conditions have been met.

delete

Removes the named key and value pair from a Squirrel table.

do

Marks the start of a do... while loop structure in which the condition for execution of the code within the structure is evaluated each time the loop completes, ie. the loop will always be executed at least once.

else

May be used as part an if conditional structure to indicate code to be run if the if statement’s condition is not met.

enum

Marks the following identifiers as a series of sequential constants and populates them according to the given value.

extends

Used as part of a class definition, it indicates that the class inherits the methods and properties of the named parent.

false

One of two possible Boolean outcomes of a conditional statement.

for

Defines a loop structure using an index variable. The statement includes the initial state of the index variable, the condition that must be met for the loop to end, and an expression to increase or decrease the value of the index variable each time the loop is executed.

foreach

Defines a loop structure by stepping through all the members of a collection data structure such as an array or table. Since Squirrel classes and class instances are stored in table structures, their members may also be stepped through in a foreach loop.

function

Marks the following block of code as a function.

if

Indicates a block of code which will be executed only if the accompanying expression evaluates to true.

in

Checks for the presence of a name entity within the members of a collection data structure such as an array or table. Since Squirrel classes and class instances are stored in table structures, their members may also be tested using in.

instanceof

Tests if an object is an instance of a particular class.

local

Marks the following variable’s scope as being local to the context or structure in which it is being defined.

null

Squirrel’s name for a zero-value quantity.

resume

Triggers the execution of a generator function previously suspended with a yield statement.

return

Triggers the end of the execution of a function and returns the following value, if any.

static

Marks a scalar properties of a class as common to all instances of that class, ie. all instances share the variable. In Squirrel, all non-scalar members of a class are implicitly static, but can be made unique to the instance by assigning them in a constructor function.

switch

Marks the start of a conditional structure in which the following variable is compared to a series of case values and code executed from the point at which the case value and variable value coincide. Execution continues from this point to the end of the structure unless a break statement is included.

this

An implicit parameter passed to all functions, it contains a reference to the function’s context object.

throw

May be included within code that has been placed in the try section of a try... catch structure to force the generation of an exception which will then be dealt with by the code in the catch section.

true

One of two possible Boolean outcomes of a conditional statement.

try

Part of a try... catch structure, it indicates code to be run which might generate an exception. If this occurs, the exception is passed to the catch section for processing.

typeof

Indicates a variable’s data type; the type is returned as a lower-case string.

while

Defines the condition for the looped execution of a block of code. In a do... while loop structure, the condition is evaluated each time the loop completes, ie. the loop will always be executed at least once. In a simple while... structure, the condition is evaluated before the loop code is executed.

yield

Indicates a function is a generator and marks the point at which execution of the function code will be suspended and its state preserved. Execution will not continue until the calling code includes a resume statement.