Skip to content

Data Network

Overview

The Data Network in CC: Computer Energetics provides functions for sending messages, publishing persistent states, handling network events, and interacting with monitors and speakers across pins or hubs.


Calling Conventions / Prefixes

All methods within the Data Network section are accessed through the global cee namespace:

cee.send(pin, data)
cee.publish(pin, key, value)

API Reference Table

Method Signature Arguments & Types Description
cee.send(pin, data) pin (number), data (any) Sends data over a pin; returns how many computers received it.
cee.publish(pin, k, v) pin (number), k (string), v (any) Publishes a latest value, overwriting instead of queueing.
cee.readState(id, key) id (number), key (string) Reads the newest value that a sender published.
cee.states() None Returns every named value this computer holds.
cee.getMonitor(pin, n) pin (number), n (number, optional) Returns a terminal handle for a screen on the pin.
cee.getMonitors(pin) pin (number) Returns one terminal handle per screen on the pin.
cee.getSpeaker(pin, n) pin (number), n (number, optional) Returns a speaker handle for a speaker on the pin.
cee.getSpeakers(pin) pin (number) Returns one handle per speaker on the pin.
cee.getDataScriber(pin, n) pin (number), n (number, optional) Returns a scriber handle for a scriber on the pin.
cee.getDataScribers(pin) pin (number) Returns one handle per scriber on the pin.

Lua Code Examples

Example 1: Sending Data Over a Pin

local pin = 3
local sentCount = cee.send(pin, "Hello computers!")
print("Delivered to " .. sentCount .. " computers.")

Example 2: Publishing and Reading State

-- Sender
cee.publish(3, "speed", 42)

-- Receiver (handling cee_state event)
local _, pin, id, k, v = os.pullEvent("cee_state")
local latest = cee.readState(id, "speed")
print("Latest speed from " .. id .. ": " .. latest)