Documentation
Language
Everything is an Expression!
Literally. Assignments, loops, even an entire script file. Everything is an expression. Tablescript evaluates each expression in turn. Some constructs (loops, conditionals, functions, tables, etc.) “return” values but really they don’t; they evaluate to values.
This is important to know as a Tablescript developer.
You will find no return
statements. Or break
or continue
inside loops. You might find you have to think about code differently to the way you’d write it in JavaScript or PHP.
For instance, in JavaScript you might write something like this:
while (true) {
doAThing();
if (checkCondition()) {
break;
}
doAnotherThing();
...
}
In Tablescript, you would write the same thing as:
This might seem overly restrictive, but it really isn’t. It actually encourages you to write more, smaller functions.
Conditionals
Conditionals come in two varieties: if/else expressions, and ternary expressions.
If/Else
if
and else
work like in other languages, with the exception that the entire expression evaluates to the last value in the selected branch. For example:
result
will be assigned the value ‘greater’ because x
is greater than 2 and the first expression (the if clause) is evaluated. If x
was 1, the else clause would be evaluated and result
would be ‘less than’.
Ternary ( ?: )
Ternary operators work like in other languages. If the test is true, the first clause is evaluated. Otherwise, the second clause is evaluated. For example:
In most cases, using a ternary operator will make your code more succinct, but you risk confusing the reader if your tests or clauses are complex. They both accomplish the same thing and can often be swapped for the other with little effort.
Loops
Tablescript supports 3 types of loops: for/in, while, and until.
For Loops
Tablescript supports bounded loops over arrays.
For loops are expressions, just like everything else. Their value is the value of the last expression evaluated inside the loop.
The range()
built-in is particularly useful here:
While Loops
While loops are unbounded and loop until their test condition is false
.
While loops are also expressions and have the value of the last expression evaluated inside the loop.
Until Loops
Until loops are unbounded and loop until their test condition is true
.
Until loops are also expressions and have the value of the last expression evaluated inside the loop.
Operators
Standard math operators: +
, -
, *
, /
, and %
.
Standard logic operators: and
, or
, and not
.
Standard comparison operators: ==
, !=
, <
, >
, <=
, and >=
.