A settings management module for ComputerCraft that provides interactive configuration with automatic validation, peripheral detection, and persistent storage using CC settings. Features: Interactive peripheral selection with type filtering, number input with range validation, string input with default values, boolean selection with menu interface, automatic settings persistence, peripheral availability checking and recovery, side-only peripheral filtering, and optional form UI integration.
formui
Recommended: Install via installer (handles dependencies automatically):
This pattern downloads and runs libraries at runtime, automatically installing any that are missing:
-- Auto-install and require libraries
local libs = {"s"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local s = require(libDir .. "s")
-- Use the library
-- (your code here)
This example shows how to download and use libraries with automatic installation:
-- Auto-install and require libraries
local libs = {"s"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local s = require(libDir .. "s")
-- Use the library
local s = require("s")
local modem = s.peripheral("modem", "modem", true)
local port = s.number("port", 1, 65535, 8080)
local name = s.string("server_name", "MyServer")
local enabled = s.boolean("enabled")
local s = require("s")
local form = s.useForm("My App Configuration")
local modem = form.peripheral("modem", "modem", true)
local port = form.number("port", 1, 65535, 8080)
local name = form.string("server_name", "MyServer")
local enabled = form.boolean("enabled")
if form.submit() then
print("Settings saved!")
print("Modem:", modem())
print("Port:", port())
end
module.peripheral(name, type, sideOnly?)Get or configure a peripheral setting with automatic validation and recovery
name (string): The setting name to store/retrievetype (string): The required peripheral type (e.g., "modem", "monitor")sideOnly? (boolean): If true, only allow peripherals attached to computer sidesmodule.number(name, from?, to?, default?)Get or configure a number setting with range validation
name (string): The setting name to store/retrievefrom? (number): Minimum allowed value (nil for no minimum)to? (number): Maximum allowed value (nil for no maximum)default? (number): Default value if user provides empty inputmodule.string(name, default?)Get or configure a string setting with optional default value
name (string): The setting name to store/retrievedefault? (string): Default value if user provides empty inputmodule.boolean(name)Get or configure a boolean setting using an interactive menu
name (string): The setting name to store/retrievemodule.useForm(title?)Create a form-based settings interface using formui.lua Requires formui.lua to be installed. Returns a table with form-based versions of all s.lua functions. local s = require("s") local form = s.useForm("My App Configuration") local modem = form.peripheral("modem", "modem", true) local port = form.number("port", 1, 65535, 8080) local name = form.string("server_name", "MyServer") local enabled = form.boolean("enabled") if form.submit() then print("Settings saved!") print("Modem:", modem()) print("Port:", port()) end
title? (string): The form title (defaults to "Settings")formInterface.peripheral(name, type, sideOnly?)Add a peripheral field to the form
name (string): The setting nametype (string): The peripheral type to filter forsideOnly? (boolean): If true, only show peripherals attached to computer sidesformInterface.number(name, from?, to?, default?)Add a number field to the form
name (string): The setting namefrom? (number): Minimum allowed valueto? (number): Maximum allowed valuedefault? (number): Default valueformInterface.string(name, default?)Add a string field to the form
name (string): The setting namedefault? (string): Default valueformInterface.boolean(name)Add a boolean field to the form
name (string): The setting nameformInterface.submit()Add submit and cancel buttons, then run the form