Guide to NTSL2

Overview
NTSL is the programming language used aboard the Station for modular computers, you can design a lot of interesting things with it, this guide will act as a starting place and reference for enterprising programmers aboard the Aurora.

String Library
String Library

Syntax

 * Variables must start with a letter, but can otherwise contain any alphanumeric character. Variables can be assigned to with name = value. Local variables can be made with var name = value or local name = value.


 * Tables are values that can be indexed and can contain multiple values. They are also sometimes referred to as lists. They are constructed in the format {key1 = value1, key2 = value2, key3 = value3...}. The final value can have a comma after it, but it is not mandatory. Tables can be indexed in the form name[index].

}
 * Functions can be made in the following format: function funcname(arg1[ = defaultvalue1], arg2[ = defaultvalue2]){	...code...
 * Arguments can have any name a variable can take, and can be assigned default values.


 * Varargs are also usable:	function funcname(... args){...code...}


 * The various arguments provided to the function will be combined into a list and stored in the local variable args, or whatever name is provided. Brackets for arguments are optional if you have an anonymous function with one argument: funcname = function arg{...code…}


 * They can even be constructed in lambda calculus style: (arg1[=defaultvalue1], arg2[=defaultvalue2]) => {...code…} In the function style, function can be abbreviated to func. Varargs can also be used in the lambda calculus style. Single variable lambda calculus functions can be further simplified into the form arg => {...code...}


 * Member functions of an object can be called in the form object.function(object, other_arguments) or object::function(other_arguments). These function identically.


 * Strings can be constructed in three ways: "content", ‘content’, or `content`.


 * These are functionally identical except for in the last case, where expressions in square brackets will be evaluated and inserted into the string. This means that `con[expression]tent` is equivalent to instead performing two concatenation operations and one tostring call, "con" .. tostring(expression) .. "tent"

Program Flow/Structure
IF/ELSE conditionals are part of the main program flow: if(condition){ ...code… } else { ...code... }
 * IF/ELSE:

WHEN conditionals are similar to IF conditionals, but are asynchronous and occur outside of the main program’s flow. They also expose their ‘arguments’ to the scope of its block. A typical case is the topic variable which is set in term.topic events. when(event){ ...code… }
 * WHEN:

WITH block exposes a list/table to the scope of its block, typically used for making library referencing easier: with(event){ ...code... }
 * WITH:

An example is used in Telecomms scripts to save the constant references to tcomm: with(tcomm){ when onmessage{ broadcast(...) }	}

FOR loops have two alternate forms. List Iteration FOR Loop: for([var] in [list]){ ...code... }	In this form, it iterates over the contents of [list], setting [var] equal to them one at a time. [list] can instead be an iterator function as well, such as string.gmatch OR Variable Iteration FOR Loop: for([i]=[initial]; [condition]; [step]){ ...code... }	Where [i] is any variable, [initial] is the initial value, [condition] is any condition (presumably involving said variable, but not necessarily), [step] is some form of increment/decrement such as i++ or i--, ++i or --i, etc. This runs the for loop until [condition] is false, executing [step] after every iteration.
 * FOR:

while(condition){ ...code... }
 * WHILE loop:

Evaluates [condition], runs whichever code block corresponds to that condition or, if none is found, the default. If a break or return isn’t reached, the program will fall through to the next condition. switch(condition){ :[default OR expression] ...code... :[default OR expression] ...code… …	}
 * SWITCH block:

Evaluates [expression], if [expression] is true returns [on_true], otherwise returns [on_false]. expression ? on_true : on_false
 * Ternary:

A very powerful, very dangerous function. Produces a function from NTSL2+ code contained in a string. Format is eval [expression].
 * Eval:

Takes the form of either @operator or @expression. In the case of an operator, returns a function that behaves like that operator (With priority to binary operators). So @+ is equivalent to (a,b)=>a+b, though runs slightly faster. When an expression is used, this functions as a niladic operator, so is equivalent to =>expression. +, -, *, /, ^, %, and/&&, or/||, <, >, <=, >=, ==, and != all operate as expected. Concatenation is performed by [expr1] .. [expr2]. The length of the text representation of a string, or the number of elements in a list, can be found with #[expression]. Logical negation is performed with ![expression], binary negation is performed with ~[expression], decimal unary negation is performed with -[expression]. Integer division can be performed with [expression] // [expression]. Modulo can be performed with [expression] % [expression]. Bitwise operators are also available, such as |, &, <<, >>, &, and [expression] ~ [expression] (xor, do not confuse with unary base 2 negation)
 * Deop Operators: