Skip to content

Stackup

Syyrion edited this page Nov 6, 2022 · 6 revisions

A brief introduction to Stackup

Stackup is a procedural, stack-oriented, RPN scripting language designed specifically for the quick creation and prototyping of patterns. Stackup has been made as barebones as possible and lacks most features of typical languages. There is only one type: numbers, which behave exactly like Lua numbers. There are no functions and no variables except for a few predefined globals.

Syntax

Basics

A number by itself will be pushed to the stack. All instructions are delimited by any whitespace.

Initial Stack Code Resulting Stack
0 1 2 3 0 1 2 3
4 dup 4 4
0 1 swap 1 0
0 1 2 3 3 1 roll 0 2 3 1

Arithmetic

Initial Stack Code Resulting Stack
1 2 + 3
1 2 - -1
1 2 * 2
1 2 / 0.5
1 2 % 1
-0.5 floor -1
-0.5 ceil 0
-0.5 abs 0.5

Logic

Zero is falsy, everything else is truthy.

Initial Stack Code Resulting Stack
0 1 and 0
0 1 or 1
0 not 1
7 not 0
-5 not 0

Control Flow

Initial Stack Code Resulting Stack
0 1 2 3 while end
3 for 0 swap end 0 0 0
1 if 5 end 5
0 if 2 else 3 end 3
2.5 1 if floor else ceil end 2

Patterns

#restrict Preprocessor

Lua Interop

The call: instruction can be used to add a function event to the timeline to call a Lua function at a specific time. First, a number is popped to determine how many arguments the Lua function should recieve. Then that amount of numbers are popped from the stack and are passed to the Lua function.

2 1 9 6

4 call:X

The stack is empty after the above code is run. The function linked to the character 'X' is shown below.

function (a, b, c, d)
    assert(a == 2)
    assert(b == 1)
    assert(c == 9)
    assert(d == 6)
end

Note: The Lua function is added to the Patternizer timeline so Patternizer:run() or Patternizer.step() must be running for the function to be called. Due to this, Stackup also cannot receive any return values from the function.

Comments

Stackup supports C style single line comments.

// This is a comment.

Clone this wiki locally