Skip to content

Syntax reference

Felipe Martínez edited this page Apr 9, 2020 · 25 revisions

A LS script is executed sequentially from top to bottom. The script is composed only of top-level case.

Case blocks

Conditional cases

Only executed if the condition evaluates to 1.

when <expression>
    ...
end

Unconditional cases

Will be executed regardless of the machine's state.

any
    ...
end
once
    ...
end
  • any cases will always be executed, regardless of the machine's state
  • once cases will only be executed once (up to machine implementation, usually on first update)

Expressions

Number literals

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

Slot accessors

Slots represent a machine's input and output. Only input (in) and memory (mem) slots can be used as expressions. Slots can be accessed raw or be indexed. The number inside an indexer will always be treated as a decimal number.

in
in[123]

Operators

All operators operate on numbers.

Binary operators (binary as in two operands)

  • Bitwise operators:
    • AND &
    • OR |
  • Arithmetic operators:
    • Add +
    • Subtract -
    • Multiply *
    • Divide /
  • Comparison operators:
    • Equals ==
    • Greater >
    • Greater or equal >=
    • Lesser <
    • Lesser or equal <=

Unary operators

  • Negation !
    • Will negate all bits of a number

Explicit operators

  • Aggregation operators:
    • Will combine a number's bits into a single bit
    • AND and
      • and(1010) == 0
    • OR or
      • or(1010) == 1
  • Truncate trunc
    • Will remove a number's zero-bits on the left side
    • trunc(00011) == 11

Clone this wiki locally