Created API/Component (markdown)

Florian Nücke 2013-12-04 14:58:28 -08:00
parent c6e9d8f9ed
commit 4fb1465f56

17
API-Component.md Normal file

@ -0,0 +1,17 @@
The component API is used to access and interact with components available to a computer. Also see [[the page on component interaction|ComponentAccess]].
- `component.get(address: string, componentType: string): string | (nil, string)`
Tries to resolve an abbreviated address to a full address. Returns the full address on success, or `nil` and an error message otherwise. Optionally filters by component type.
- `component.isAvailable(componentType: string): boolean`
Checks if there is a primary component of the specified component type.
- `component.getPrimary(componentType: string): table`
Gets the proxy for the primary component of the specified type. Throws an error if there is no primary component of the specified type.
- `component.setPrimary(componentType: string, address: string)`
Sets a new primary component for the specified component type. The address may be abbreviated, but must be valid if it is not `nil`. Triggers the `component_unavailable` and `component_available` signals if set to `nil` or a new value, respectively.
Note that the component API has a metatable that allows the following syntax:
```lua
local rs0 = component.getPrimary("redstone")
local rs1 = component.redstone -- syntactic sugar
print(rs0 == rs1) -- true
```