gahxke/sysfs_luau
access sysfs from lune!
sysfs.luau
access linux sysfs from lune!
Documentation
sysfs
Represents the root sysfs interface.
Methods:
sysfs:class(className: string) -> DeviceClass
- Returns a device class inside /sys/class.
sysfs:listClasses() -> {string}
- Lists all device classes available in /sys/class.
Example:
local sys = require("/path/to/sysfs.luau")
local netClass = sys:class("net")
local classes = sys:listClasses() --[[ {
"pwm",
"thermal",
"powercap",
"usbmisc",
...]]--
DeviceClass
Represents a device class directory in /sys/class.
Properties:
path: string - Path to the class directory.
Methods:
DeviceClass:device(name: string) -> AttributeIO
- Access a specific device inside this class.
DeviceClass:list() -> {string}
- List all devices in this class (directories only).
Example:
local eth0 = netClass:device("eth0")
local devices = netClass:list() -- e.g., {"eth0", "lo"}
AttributeIO
Represents a specific device, allowing read and write operations on its attributes.
Properties:
path: string — Path to the device directory.
Methods:
AttributeIO:read(attribute: string) -> string | number
- Reads an attribute. Returns a number if the content is numeric, otherwise a string.
AttributeIO:readBool(attribute: string) -> boolean
- Reads an attribute as a boolean ("0" → false, "1" → true).
AttributeIO:write(attribute: string, content: string | number)
- Writes a string or number to an attribute. Requires root permissions.
AttributeIO:writeBool(attribute: string, content: boolean)
- Writes a boolean to an attribute as "0" or "1". Requires root permissions.
Example:
local eth0 = netClass:device("eth0")
local mtu = eth0:read("mtu") -- 1500
local up = eth0:readBool("carrier") -- false
eth0:write("mtu", 1500)
eth0:writeBool("carrier", true)
License
This project is licensed under the GNU General Public License v2.0-or-later.