Skip to content

Memory & Stack ​

Chip Internal Memory ​

Each chip has 512 memory addresses (0–511) that persist across ticks and across save/load:

lua
-- Read from chip memory address 0
local value = mem_read(0)

-- Write to chip memory address 10
mem_write(10, 42.5)

-- Clear all chip memory
mem_clear()

Housing LED note: mem_read, mem_write, and mem_clear flash the IC housing memory light, matching the memory-style operations players expect from vanilla.

TIP

Chip memory is the easiest way to persist simple values across save/load — no ic.persist needed. For tables or strings, use ic.persist.

External Device Memory ​

Read/write another device's memory:

lua
-- Read address 5 from device on d0
local value = mem_get(0, 5)

-- Write value to address 5 on device d0
mem_put(0, 5, 100)

-- Clear all memory on device d0
mem_clear_device(0)

-- By reference ID
local value = mem_get_id(deviceId, 5)
mem_put_id(deviceId, 5, 100)
mem_clear_id(deviceId)

Logic Sorter (device memory) ​

The Logic Sorter stores its filter program as 64-bit values in device memory (same addresses you reach with IC10 get / put on the sorter pin). StationeersLua does not build those words for you, but it exposes the game's opcode and compare enums so literals stay readable:

  • ic.enums.SorterInstruction — None, FilterPrefabHashEquals, FilterPrefabHashNotEquals, FilterSortingClassCompare, FilterSlotTypeCompare, FilterQuantityCompare, LimitNextExecutionByCount
  • ic.enums.ConditionOperation — Equals, Greater, Less, NotEquals

Use mem_put / mem_get (or *_id) with the sorter's device index or reference id. Row layout and bit packing are vanilla game behavior; the Logic Sorter (community wiki) documents how to assemble each word.

See also Enumerations & Constants.

Stack Operations ​

The chip has an internal stack (shared with memory). These map directly to IC10 push/pop/peek/poke:

lua
stack_push(42)           -- Push value onto stack
local top = stack_peek() -- Read top without removing
local val = stack_pop()  -- Pop from top

stack_poke(5, 100)       -- Write directly to stack address 5

-- Stack/return address pointers
local sp = stack_get_sp()
stack_set_sp(0)

local ra = stack_get_ra()
stack_set_ra(0)

Housing LED note: stack_push, stack_pop, and stack_peek flash the IC housing memory light like vanilla push / pop / peek. stack_poke matches vanilla poke and does not flash.

INFO

In Lua, you'll almost always use local variables and tables instead of the IC10 stack. These functions exist for IC10 compatibility and for communicating with vanilla IC10 chips via shared memory.

Function Reference ​

FunctionReturnsDescription
mem_read(addr)numberRead chip memory
mem_write(addr, value)—Write chip memory
mem_clear()—Clear all chip memory
mem_get(dev, addr [, net])numberRead device memory
mem_put(dev, addr, value [, net])—Write device memory
mem_clear_device(dev [, net])—Clear device memory
mem_get_id(id, addr [, net])numberRead device memory by ID
mem_put_id(id, addr, value [, net])—Write device memory by ID
mem_clear_id(id [, net])—Clear device memory by ID
stack_push(value)—Push to stack
stack_pop()numberPop from stack
stack_peek()numberPeek top of stack
stack_poke(addr, value)—Write to stack address
stack_get_sp()numberGet stack pointer
stack_set_sp(value)—Set stack pointer
stack_get_ra()numberGet return address
stack_set_ra(value)—Set return address

⚠️ This documentation was AI-generated and may contain inaccuracies. Please submit pull requests with corrections as needed.