-
Notifications
You must be signed in to change notification settings - Fork 3
Syntax reference
A LS script is executed sequentially from top to bottom. The script is composed only of top-level cases.
Slots represent a machine's input and output, and can be raw or indexed. The number inside an indexer will always be treated as a decimal number.
A value will be considered "true" if it is greater than 0. If you instead want to check for a value equal to 1, use the equality operator (x == 1)
Comments can be started with a # anywhere on a line.
Only executed if the condition evaluates to a truthy value.
when <expression>
...
end
Will be executed regardless of the machine's state.
any
...
end
once
...
end
-
anycases will always be executed, regardless of the machine's state -
oncecases will only be executed once (up to machine implementation, usually on first update)
LogicScripts distinguishes between binary and decimal numbers through the use of a suffix apostrophe ('). All decimal numbers must be suffixed, even if they contain digits other than 0 and 1, to prevent mistakes and confusion.
1010
123'
123 # Invalid, throws warning
Only input (in) and memory (mem) slots can be used as expressions.
in
in[123]
Accepts multiple expressions in list form and combines them into a single number
(expr1, expr2, expr3, ...)
All operators operate on numbers.
- Bitwise operators:
- AND
& - OR
|
- AND
- Arithmetic operators:
- Add
+ - Subtract
- - Multiply
* - Divide
/
- Add
- Comparison operators:
- Equals
== - Greater
> - Greater or equal
>= - Lesser
< - Lesser or equal
<=
- Equals
- Negation
!- Will negate all bits of a number
- Aggregation operators:
- Will combine a number's bits into a single bit
- AND
andand(1010) == 0
- OR
oror(1010) == 1
- Sum of bits
sumsum(110011) == 4
- Truncate
trunc- Will remove a number's zero-bits on the left side
trunc(00011) == 11
Contained inside cases or other statements.
Assign a value to a slot. Only output (out) and memory (mem) slots can be assigned to.
out = 1010
mem[1] = 1
Will execute a block of statements if a condition is evaluated to a truthy value.
if <expression>
...
end
if <expression>
...
else
...
end