Skip to content

Storage

FilaSignal has two kinds of named storage. Both keep copies of values under string keys.

Drive storage Storage Server
Used by the drive’s own program, as storage every program on the network, through a reference
Capacity 64 KiB, 256 keys 256 KiB, 1,024 keys, 64 KiB per value
Lives in the world save, with the drive in the block; deleted when the block breaks
Read by a computer drives.from(name).read(key) directly

nil, booleans, numbers, strings, lists, tuples and dictionaries, nested at most 16 levels, without loops. Device handles and references, constants, class objects and errors cannot be stored. Every read returns a fresh copy: change it and write it back to update the stored value.

Keys are 1 to 64 characters: letters, digits and _ . : -.

A write is checked completely before anything changes, so a failed write leaves storage as it was.

storage.append(key, value)

Append a value to the list under a key, creating it when absent.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.write. Cost: 16 operations.

ok, err = storage.append("history", entry)

storage.clear()

Remove every stored key.

Gives: bool, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.write. Cost: 16 operations.

ok, err = storage.clear()

storage.delete(key)

Remove a key. Returns false when it was absent.

Parameters: key: string. Gives: bool, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.write. Cost: 16 operations.

removed, err = storage.delete("history")

storage.has(key)

Test whether a key is stored.

Parameters: key: string. Gives: bool, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.read. Cost: 16 operations.

found, err = storage.has("history")

storage.keys()

List stored keys in insertion order.

Gives: list, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.read. Cost: 16 operations.

keys, err = storage.keys()

storage.read(key)

Read a copy of a stored value. A missing key returns storage.missing.

Parameters: key: string. Gives: any value, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.read. Cost: 16 operations.

last, err = storage.read("last_detection")

storage.usage()

Read used and capacity bytes and entries and maxEntries.

Gives: dict, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.read. Cost: 16 operations.

usage, err = storage.usage()

storage.write(key, value)

Store a copy of a value under a key, replacing any old value.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: drive.damaged, drive.in_use, drive.missing, host.denied, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: storage.write. Cost: 16 operations.

ok, err = storage.write("last_detection", entry)

Properties: records.connected, records.id, records.kind, records.name. They are read-only.

records.append(key, value)

Add a value to the end of the list under a key, creating the list when needed.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.append("visitors", name)

records.clear()

Remove everything stored on the server.

Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.clear()

records.delete(key)

Remove a key. Gives false when nothing was stored.

Parameters: key: string. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.delete("old")

records.has(key)

True when something is stored under a key.

Parameters: key: string. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

if server.has("diamonds") { print("stocked") }

records.keys()

List the stored keys, oldest first.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

names = server.keys()

records.read(key)

Read a copy of the value stored under a key. A missing key gives the error storage.missing.

Parameters: key: string. Gives: any value, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

count = server.read("diamonds")

records.usage()

Read used and capacity bytes and entries and maxEntries.

Gives: dict, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

space = server.usage()

records.write(key, value)

Store a copy of a value under a key, replacing any old value.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.write("diamonds", 64)
Code Meaning
storage.missing Nothing is stored under the key.
storage.key The key is empty, too long or has other characters.
storage.value The value cannot be stored, for example a device or a class object, or it nests too deeply.
storage.type append on a key that holds something other than a list.
storage.full The write would exceed the capacity or the number of keys.
storage.damaged A Storage Server’s saved data could not be read. It is kept unchanged for an operator.
drive.missing, drive.in_use, drive.damaged The drive is gone, in use elsewhere, or its record is damaged.
host.denied A drive program wrote to a Storage Server that only lets device programs read.

Storage fills up when a program appends forever. Keep only the newest entries:

on device.entityEnter(entity) {
history, err = storage.read("history")
if err is not nil {
history = []
}
history.append(entity.name)
while history.length > 50 {
history.remove(0)
}
storage.write("history", history)
}