Keywords - LightningLaser8/ISL GitHub Wiki

Variables

Declaration / Creation

Variables are created with static types, and must be declared before attempting to use them.

Syntax

number <name>
Creates a variable with a value of 0, and type number.

string <name>
Creates a variable with a value of "", and type string.

(deprecated) declare var <name>
Creates a variable with a value of null, and type undefined. THis will cause errors everywhere, so don't use it.

Deletion

delete Deletes a variable, allowing redeclaration.

Syntax

delete <variable>
Deletes the specified variable.

Value Setting

set Sets a variable's value.

Syntax

set <variable> <value>
Sets the specified variable's value to the specified value.

set <variable>
Sets the specified variable's value to null. Acts as a redeclaration.

Addition

add Adds to or concatenates a variable's value with another value.

Syntax

add <variable> <value>
Adds the specified value to the specified variable's value.
If one or more of the values are strings, the values will be concatenated instead.

Subtraction

subtract Subtracts a number from a variable's value.

Syntax

subtract <variable> <number>
Subtracts the specified value from the variable's value.

Multiplication

multiply Multiplies a variable's value by a number.

Syntax

multiply <variable> <number>
Multiplies the specified variable's value by the specified number.

Division

divide Divides a variable's value by a number.

Syntax

divide <variable> <number>
Divides the specified variable's value by the specified number.

Rounding

round Rounds a variable to the nearest integer.

Syntax

round <variable>
Rounds the specified variable to the nearest integer.

Negation

negate Sets a variable to its negative value. e.g. 1 becomes -1, -3.2 becomes 3.2.

Syntax

negate <variable>
Negates the specified variable.

Exponentiation

exponent Raises a variable's value to the power of a number.

Syntax

exponent <variable> <power>
Raises the specified variable's value to the specified power. e.g. exponent x 2 would square x.

Inverse Exponentiation / Roots

root Sets a variable's value to the specified root of its current value.

Syntax

root <variable> <root>
Sets the specified variable's value to the specified root of its current value. e.g. root x 2 would square root x.

Functions

Function Creation

function can be used to create a function, a block of code that can be called multiple times in one program, and optionally take parameters. end Ends a function declaration.

Syntax

(deprecated) declare cmd <name>
function <name> [parameters]
Starts a function with the specified name and parameters.
end <name>
Ends the specified function declaration.

Parameters

Each parameter is declared as name:type, for example divisor:number, where the parameter divisor is created as a number. The parameter can then be accessed just like a local variable, but read-only. Parameters take precedence over variables.

Function Execution

execute Runs a function, then returns to the line number it was called from, and continues as normal.

Syntax

execute <name> [arguments]
Runs a function with the specified name, passing in the arguments t obe used within the function as parameters..

Accepted Labels

default Uses the default for each type as the parameter, i.e. 0 for number, blank string for a string, etc.

Flow Control

Jumping to a Line

jump Jumps to a line number.

Syntax

jump <line>
Jumps to line line.

Relative Line Numbers

~<number> can be used to indicate relative line nmbers, e.g. ~2 indicates 2 lines ahead.

Stopping Execution

stop Halts execution of the program.

Syntax

stop
Stops the program.

Restarting Execution

Stops execution, then starts it again at the same speed.
Restarts from line 1, with all variables cleared.

Syntax

restart
Jumps to line 1, and deletes all local variables.

Accepted Labels

non-destructive Does not delete local variables. Instead, marks them as re-declareable.

Pausing Execution

pause Pauses execution of the program.
Does not alter line number or local variables, just simply stops execution.

Syntax

pause <timeout>
Pauses execution for the specified number of instructions.

Changing Run Delay

rundelay Changes the interpreter's execution speed.

Syntax

rundelay <delay>
Sets the delay to the specified number of milliseconds.

Conditional Statements / Selection

if Runs an ISL statement if the condition is met.

Syntax

if <value1> <operator> <value2> <code>
Runs the code code if the condition is met. code can be any valid ISL code string.
Condition is made with value1, value2 and the operator.

Valid Operators:

  • = Checks equality. Checks if value1 is the same as value2. Coerces types.
  • < Checks if value1 is less than value2.
  • > Checks if value1 is greater than value2.
  • != Checks inequality. Checks if value1 is different to value2. Coerces types.
  • in Checks if the value1 string appears in value2.

Chaining

if can be chained indefinitely by placing the next statement as the code of the last, and all conditions are checked at once.

Groups

The in operator can take a list or group of items to check exactly against. These groups are denoted by square brackets, and each item is separated by a vertical pipe |, i.e. [item1|item2|"item 3"]. Everywhere else, this is just a string.

IO

[!] Most IO ISL requires web-enabled environment. To ensure constant operation, use {environment: "web"} or {environment: "js"} in the options parameter in the ISLInterpreter constructor.

Message Logging

log Logs a message to the interpreter's console.
flush Logs the interpreter's internal console to the browser's console.

Syntax

flush
Logs all messages in the interpreter's console to the browser's console.
All log statements are put in the same line. log <message>
Logs a message to the interpreter's console.

Accepted Labels (flush)

separated Puts separate log statements in separate lines.

Awaiting Key Presses / Keyboard Input

awaitkey Sets a variable to the next key pressed. Pauses until a key is pressed.

Syntax

awaitkey <variable> [type] Listens for a key press, then manipulates the specified variable with it.
type can be set or add, default is set

Getting Key Presses / Keyboard Input

getkeys Sets a variable to all currently pressed keys, joined as one string. Does not pause execution.

Syntax

getkeys <variable> [type] Gets all pressed keys as a string, then manipulates the specified variable with it.
type can be set or add, default is set
Pressed keys are given as a comma-separated string, e.g. holding 'a', 'b', and 'c' gives a,b,c.

Accepted Labels

grouped Gives keys as a group: [...|...]

Prompting / Text Input

webprompt Opens the browser's default prompt popup, and assigns a variable to the input.

Syntax

webprompt <variable> <prompt>
Opens a popup with the given text to give input. Once the input has been processed, sets the variable to the given value in the prompt.

Graphics

The use of ISL to create and manipulate a HTML canvas element. This entire section can be disabled with the ISLInterpreter.allowIndependentGraphics option.

Creating a Canvas

canvas Creates a new canvas element, or resizes the existing one.

Syntax

canvas <width> <height>
Creates a new canvas. If one already exists in the interpreter, it will be resized to the new dimensions.
Dimensions are width by height.

Drawing Rectangles

[!] Requires a canvas to have been made It's all very well and good having a canvas, but in order for anything to show up, something needs to be drawn.
rectangle Draws a rectangle somewhere on the canvas.

Syntax

rectangle <x> <y> <width> <height> [centred]
Draws a rectangle at x,y on the canvas (0,0 is the top-left corner) with width width and height height.

Accepted Labels

filled Draws a solid block.
hollow Draws a hollow outline of the rectangle.
Default is both of the above at once.

Drawing Circles

[!] Requires a canvas to have been made Because r o u n d. circle Draws a circle somewhere on the canvas. ellipse Draws an ellipse; a circle with different width and height.

Syntax

circle <x> <y> <radius> [centred]
Draws a circle at x,y on the canvas (0,0 is the top-left corner) with radius radius. ellipse <x> <y> <width> <height> [centred]
Draws an ellipse at x,y on the canvas (0,0 is the top-left corner) with radii width and height.

Accepted Labels

filled Draws a solid circle.
hollow Draws a hollow outline of the circle.
Default is both of the above at once.

Styling

Does not actually require a canvas.
This allows you to change what those rectangles look like. fill Sets fill colour
outline Sets outline colour and optionally width.

Syntax

fill <colour> [alpha]
Sets the fill colour to the specified colour. colour can be any CSS colour string, or a hex code in the form #rrggbb. alpha must be a number between 0 and 255, or not present at all. Only works if colour is a hex code. outline <colour> <width>
Sets the outline colour to the specified colour. colour can be any CSS colour string, or a hex code in the form #rrggbb.
If specified, changes the outline width to width.

Accepted Labels

no Sets outline width to zero, and colour to transparent. Ignores parameters.

Transformations

[!] Requires a canvas to have been made For when rotations are required.
save Saves the current drawing state, including rotations and styles to a stack.
restore Restores the most recently saved state.

Syntax

save
Saves the current state.
restore
Restores the most recently saved state.

Buffered Graphics

If the flickering is annoying (it definitely is), then ISLInterpreter has an option, bufferedGraphics that adds all draw operations to an array, then draws them all at once.
draw Draws everything in the buffer, and clears it.

Syntax

draw
Draws everything in the buffer at once.

Program Interface

In- and Exporting

import Sets a local variable's value to an external one.
export Sets an external variable's value to an internal one.
For security, the ISLInterpreter.allowExport and ISLInterpreter.allowImport options can be set to false to disable exporting and importing, respectively.
Both import and export can only access global variables, in JavaScript's case, declared with var, not let or const.

Syntax

export <local-variable> <external-variable>
Changes the specified external variable to the value of the specified local variable.
import <external-variable> <local-variable>
Changes the specified local variable to the value of the specified external variable.

Meta Tags

Meta tags are a way of adding extra info to an ISL program, to change what the interpreter does with it.
They are always surrounded by [square brackets] and are placed alone on a line, without any keywords. They cannot have dynamic values (i.e. using \variable references\)

Requiring Extensions

If an ISL program is made with a certain extension in mind, using a require tag can make sure that all users import that extension. If the file is run with a require tag, and the interpreter doesn't have the extension, an Error will be thrown.

Syntax

[require <extension>]
Flags that the file requires the specified extension.

Multiple Tags

Multiple require tags will check for all the extensions specified.

Setting Environment

Some features of basic ISL and extensions require certain environments to work, and throw errors if they're in the wrong one. However, this is only after the rest of the program has run, so can be wasteful. environment or env tags are used to declare the environment to the interpreter, so it can throw errors early.

Syntax

[environment <environment>]
[env <environment>]
Throws an error if the interpreter's environment doesn't match the specified one.

Multiple Tags

Adding this tag multiple times will require all environments at once, which is impossible, so an error will be thrown regardless.

Ignoring Keywords

ignore tags can be used to effectively 'comment out' entire keywords, and stop them being parsed.

Syntax

[ignore <...keywords>]
Adds the keyword(s) to the ignore list. Ignored keywords are passed over during interpretation. Can take a list of keywords, for example [ignore add subtract multiply divide] will ignore the keywords add, subtract, multiply and divide.

Multiple Tags

Multiple ignore tags will add all the tags to the ignore list.

⚠️ **GitHub.com Fallback** ⚠️