Memory Modules
Overview
The Memory Modules section in the cee API provides functions for interacting with and managing permanent 1 MB storage volumes across computer fabrics in a ComputerCraft/CC:Tweaked environment.
This section is essential for developers working on persistent data storage, shared filesystems across multiple computers, and storage volume attachment monitoring. The functions provided allow for fine-grained control over how programs query storage volumes and respond to mount events.
Calling Conventions / Prefixes
All methods within the Memory Modules section are accessed through the global cee namespace, meaning they can be invoked directly as:
local volumes = cee.listStorage()
local vol = cee.getStorage("mem")
These functions do not require any object instantiation and operate on the current fabric storage state. They should not be confused with methods that are part of other sections like speaker or monitor, which may have their own peripheral handles.
API Reference Table
| Signature | Arguments & Types | Description |
|---|---|---|
cee.listStorage() |
None | Volumes on this computer's fabric. |
cee.getStorage(id) |
id (string) |
One volume, by its storage id. |
Lua Code Examples
Example 1: Listing All Fabric Storage Volumes
local volumes = cee.listStorage()
for _, v in ipairs(volumes) do
print("Storage ID:", v.id)
print("Mount Path:", v.path)
print("Free Space:", v.free)
end
Example 2: Getting Specific Volume Details
local storageId = "mem"
local storageInfo = cee.getStorage(storageId)
if storageInfo then
print("Capacity:", storageInfo.capacity)
print("Used space:", storageInfo.used)
end
Example 3: Writing to Shared Fabric Storage
local f = fs.open('/mem/notes.txt', 'w')
if f then
f.write('Hello from shared memory module!')
f.close()
print("Successfully wrote to /mem/notes.txt")
end
Example 4: Monitoring Storage Attachments
print("Waiting for storage attachment...")
while true do
local _, path, id = os.pullEvent('storage_attach')
print("Storage attached at:", path, "with ID:", id)
end
Example 5: Monitoring Storage Detachments
print("Waiting for storage detachment...")
while true do
local _, path, id = os.pullEvent('storage_detach')
print("Storage detached:", id, "from path:", path)
end
Notes
- Memory modules are permanent 1 MB volumes wired via their gold pin into your fabric, automatically mounting under
/mem,/mem2,/mem3, etc., in storage ID order. - Every computer on the fabric sees the same volume under the same name and shares the files on it.
storage_detach(path, id)fires when the module loses power, leaves its bay, or stops sharing your fabric, but files survive all three.