Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:component [2014/08/12 21:36]
sangar
api:component [2018/06/15 21:50] (current)
ldentityunknown
Line 8: Line 8:
   Calls the method with the specified name on the component with the specified address, passing the remaining arguments as arguments to that method. Returns the result of the method call, i.e. the values returned by the method. Depending on the called method'​s implementation this may throw.   Calls the method with the specified name on the component with the specified address, passing the remaining arguments as arguments to that method. Returns the result of the method call, i.e. the values returned by the method. Depending on the called method'​s implementation this may throw.
 - `component.list([filter:​string[,​ exact:​boolean]]):​function`  ​ - `component.list([filter:​string[,​ exact:​boolean]]):​function`  ​
-  Returns ​an iterator over all components currently attached to the computer, ​providing tuples of address and component type. Use it like so: `for address, componentType in component.list() do ... end`+  Returns ​a table with all components currently attached to the computer, ​with address ​as a key and component type as a valueIt also provides iterator syntax via `__call`, so you can use it like so: `for address, componentType in component.list() do ... end`  
   If `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.  ​   If `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.  ​
   If `true` is passed as a second parameter, exact matching is enforced, e.g. `red` will *not* match `redstone`.   If `true` is passed as a second parameter, exact matching is enforced, e.g. `red` will *not* match `redstone`.
Line 19: Line 19:
 - `component.type(address:​string):​string`  ​ - `component.type(address:​string):​string`  ​
   Get the component type of the component with the specified address.   Get the component type of the component with the specified address.
 +- `component.slot(address:​string):​string`  ​
 +  Return slot number which the component is installed into. Returns -1 if it doesn'​t otherwise make sense.
 +- `component.fields(address:​string):​string`  ​
 +  Undocumented
 - `component.get(address:​ string[, componentType:​ string]): string | (nil, string)`  ​ - `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.   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.
Line 27: Line 31:
 - `component.setPrimary(componentType:​ string, address: string)`  ​ - `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.   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.
-- `component.list([filter:​ string]): function`  ​ +  ​ 
-  ​Returns an iterator which returns pairs of `address, type` for each component ​connected to the computer. It optionally takes filter - if specified this will only return those components for which the filter is a substring of the component type. For example: +Note that the component ​API has metatable that allows ​the following syntax:
-```lua +
-local component = require("​component"​) +
--- prints `redstone` for each attached redstone card. +
-for _, name in component.list("​red"​) do print(name) end +
-```+
  
-Note that the component API has a metatable that allows the following syntax: 
 ```lua ```lua
 local component = require("​component"​) local component = require("​component"​)
Line 42: Line 40:
 print(rs0 == rs1) -- true print(rs0 == rs1) -- true
 ``` ```
 +
 +
 Contents Contents
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}