s v2.0.1

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.

Installation

⚠️ Dependencies: This library requires: formui
Using installer will automatically install all dependencies.

Recommended: Install via installer (handles dependencies automatically):

wget run https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua s
View on GitHub →

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)

Examples

Using with Runtime Installation

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

Usage Examples

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

Functions

module.peripheral(name, type, sideOnly?)

View source on GitHub

Get or configure a peripheral setting with automatic validation and recovery

Parameters:
Returns: table # The wrapped peripheral object

module.number(name, from?, to?, default?)

View source on GitHub

Get or configure a number setting with range validation

Parameters:
Returns: number # The configured number value

module.string(name, default?)

View source on GitHub

Get or configure a string setting with optional default value

Parameters:
Returns: string # The configured string value

module.boolean(name)

View source on GitHub

Get or configure a boolean setting using an interactive menu

Parameters:
Returns: boolean # The configured boolean value

module.useForm(title?)

View source on GitHub

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

Parameters:
Returns: table # Form interface with peripheral, number, string, boolean, and submit functions

formInterface.peripheral(name, type, sideOnly?)

View source on GitHub

Add a peripheral field to the form

Parameters:
Returns: function # Getter function that returns the peripheral name

formInterface.number(name, from?, to?, default?)

View source on GitHub

Add a number field to the form

Parameters:
Returns: function # Getter function that returns the number value

formInterface.string(name, default?)

View source on GitHub

Add a string field to the form

Parameters:
Returns: function # Getter function that returns the string value

formInterface.boolean(name)

View source on GitHub

Add a boolean field to the form

Parameters:
Returns: function # Getter function that returns the boolean value

formInterface.submit()

View source on GitHub

Add submit and cancel buttons, then run the form

Returns: boolean # True if submitted, false if cancelled