The component API is used to access and interact with components available to a computer. Also see the page on component interaction.
component.doc(address:string, method:string): string
tostring
on a method in a proxy, for example tostring(component.screen.isOn)
.component.invoke(address:string, method:string[, ...]): ...
component.list([filter:string[, exact:boolean]]):function
__call
, so you can use it like so: for address, componentType in component.list() do ... end
filter
is set this will only return components that contain the filter string (this is not a pattern/regular expression). For example, component.list("red")
will return redstone
components.true
is passed as a second parameter, exact matching is enforced, e.g. red
will not match redstone
.component.methods(address:string):table
component.proxy(address:string):table
invoke
). This is what's used to generate 'primaries' of the individual component types, i.e. what you get via component.blah
.component.proxy(component.list("redstone")()).getInput(sides.north)
, which gets you a proxy for the first redstone
component returned by the component.list
iterator, and then calls getInput
on it.type
with the component's type name, and address
with the component's address.component.type(address:string):string
component.slot(address:string):string
component.fields(address:string):string
component.get(address: string[, componentType: string]): string | (nil, string)
nil
and an error message otherwise. Optionally filters by component type.component.isAvailable(componentType: string): boolean
component.getPrimary(componentType: string): table
component.setPrimary(componentType: string, address: string)
nil
. Triggers the component_unavailable
and component_available
signals if set to nil
or a new value, respectively.
local component = require("component") local rs0 = component.getPrimary("redstone") local rs1 = component.redstone -- syntactic sugar print(rs0 == rs1) -- true