Skip to content

Migrating from IC10

If you're coming from IC10 assembly, here's a quick translation guide.

Instruction Mapping

IC10Lua
alias Temp r0local temp
define PI 3.14local PI = 3.14
l r0 d0 Temperaturelocal temp = ic.read(0, LT.Temperature)
s d0 On 1ic.write(0, LT.On, 1)
ls r0 d0 0 Occupiedlocal occ = ic.read_slot(0, 0, LST.Occupied)
lb r0 HASH("GasSensor") Temperature 2local avg = ic.batch_read(hash("GasSensor"), LT.Temperature, LBM.Average)
push 42stack_push(42)
pop r0local val = stack_pop()
move r0 r1local a = b
add r0 r1 r2local a = b + c
and r0 r1 r2local a = bit_and(b, c)
j labelwhile true do ... end or goto label
beq r0 0 labelif r0 == 0 then ... end
sleep 5sleep(5)
yieldyield()
hcfhcf()

Key Differences

  1. No registers — Use Lua variables. No 16-register limit.
  2. No line numbers — Use functions, loops, and if/else. No j 5 or beq r0 0 15.
  3. Nil instead of errorsic.read() returns nil for missing devices instead of crashing.
  4. Strings are native — No ASCII-6 packing needed (but pack_ascii6 is available for IC10 interop).
  5. Tables — Use Lua tables for data structures instead of the 512-value stack.
  6. Functions — Define reusable functions instead of jal/j ra patterns.
  7. Error handling — Use pcall() for protected calls.

Network / Channel Addressing

IC10 uses d0:0 connection syntax and Channel0..Channel7 logic types. In Lua, most ic.read / ic.write variants accept an optional networkIndex parameter:

lua
local LT = ic.enums.LogicType

-- Read from device on d0, network index 0
local value = ic.read(0, LT.Temperature, 0)

-- Read all channels 0..7 from db:0 into a table
local channels = {}
for i = 0, 7 do
    channels[i] = ic.read(ic.const.BASE_UNIT_INDEX, LT.Channel0 + i, 0)
end

Numeric Formats

IC10Lua
$FF0xFF
$E1B20xE1B2
%101010No binary literal syntax in Lua 5.2 — use tonumber("101010", 2)

Hashes

IC10 uses HASH("string"). StationeersLua provides the same function:

lua
local sensorHash = hash("StructureGasSensor")
local nameHash = hash("Sensor 1")

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