Module system.hardware¶
The hardware module implements functions for operating on peripherals and other hardware devices.
Index¶
Data
A table that allows accessing device object pointers in a tree. This is simply syntax sugar for real paths. @usage To access the left redstone signal |
Function
Calls a method on a device. |
|
Returns a list of children of this device. |
|
Returns a list of wrapped devices that implement the specified type. |
|
Returns whether the device implements the specified type. |
|
Returns a table of information about the specified device. |
|
Toggles whether this process should receive events from the device. |
|
Locks the device from being called on or listened to by other processes. |
|
Returns a list of methods implemented by this device. |
|
Returns a list of device paths that match the device specifier or object. |
|
Returns a list of properties implemented by this device. |
|
Unlocks the device after previously locking it. |
|
Wraps a device into an indexable object, allowing accessing properties and methods of the device by indexing the table. |
API Reference¶
-
system.hardware.wrap(device:
string): (result:device)¶ Wraps a device into an indexable object, allowing accessing properties and methods of the device by indexing the table.
If an object is passed, this simply re-wraps the device in a new object.
@usage Wrap a device, use a property, and call a method:
local computer = hardware.wrap("/") print(computer.isOn) computer.label = "My Computer" computer:reboot()
- Parameters:
device (
string) – The device specifier or object to wrap- Returns:
result (
device) – The wrapped device
-
system.hardware.find(type:
string): (...:device)¶ Returns a list of wrapped devices that implement the specified type.
See :lua:obj:
hardware.wrap: For wrapping a single device by path- Parameters:
type (
string) – The type to search for- Returns:
... (
device) – The devices found, ornilif none were found
-
system.hardware.path(device:
string|device): (...:string)¶ Returns a list of device paths that match the device specifier or object.
If an absolute path is specified, this returns the same path back. If a device object is specified, this returns the path to the device.
- Parameters:
device (
string|device) – The device specifier or object to read- Returns:
... (
string) – The paths that match the specifier or device object.
-
system.hardware.hasType(device:
string|device, typ:any): (result:boolean)¶ Returns whether the device implements the specified type.
- Parameters:
device (
string|device) – The device specifier or object to query- Returns:
result (
boolean) – Whether the device implements the type
-
system.hardware.info(device:
string|device): (result:HWInfo|nil)¶ Returns a table of information about the specified device.
- Parameters:
device (
string|device) – The device specifier or object to query- Returns:
result (
HWInfo|nil) – The hardware info table, ornilif no device was found
-
system.hardware.methods(device:
string|device): (result:string[])¶ Returns a list of methods implemented by this device.
- Parameters:
device (
string|device) – The device specifier or object to query- Returns:
result (
string[]) – The methods available to call on this device
-
system.hardware.properties(device:
string|device): (result:string[])¶ Returns a list of properties implemented by this device.
- Parameters:
device (
string|device) – The device specifier or object to query- Returns:
result (
string[]) – The properties available on this device
-
system.hardware.children(device:
string|device): (result:string[])¶ Returns a list of children of this device.
- Parameters:
device (
string|device) – The device specifier or object to query- Returns:
result (
string[]) – The names of children of the device
-
system.hardware.call(device:
string|device, method:string, ...:any): (...:any)¶ Calls a method on a device.
- Parameters:
device (
string|device) – The device specifier or object to call onmethod (
string) – The method to call... (
any) – Any arguments to pass to the method
- Returns:
... (
any) – The return values from the method
-
system.hardware.listen(device:
string|device, state?:boolean):unknown¶ Toggles whether this process should receive events from the device.
- Parameters:
device (
string|device) – The device specifier or object to modifystate? (
boolean) – Whether to allow events (defaults to true)
-
system.hardware.lock(device:
string|device, wait?:boolean): (result:boolean)¶ Locks the device from being called on or listened to by other processes.
it’s currently locked by another process
See :lua:obj:
unlock: To unlock the device afterward- Parameters:
device (
string|device) – The device specifier or object to modifywait? (
boolean) – Whether to wait for the device to unlock if (defaults to true)
- Returns:
result (
boolean) – Whether the current process now owns the lock
-
system.hardware.unlock(device:
string|device):unknown¶ Unlocks the device after previously locking it.
See :lua:obj:
lock: To lock the device- Parameters:
device (
string|device) – The device specifier or object to modify
-
system.hardware.tree:
table|nil¶ A table that allows accessing device object pointers in a tree. This is simply syntax sugar for real paths. @usage To access the left redstone signal
local device = hardware.wrap(hardware.tree.redstone.left) print(device.input)