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
Next revision Both sides next revision
api:component [2014/08/12 21:29]
sangar
api:component [2016/06/15 08:45]
payonel [Component API]
Line 11: Line 11:
   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`.
 +- `component.methods(address:​string):​table`  ​
 +  Returns a table with the names of all methods provided by the component with the specified address. The names are the keys in the table, the values indicate whether the method is called directly or not.
 - `component.proxy(address:​string):​table`  ​ - `component.proxy(address:​string):​table`  ​
   Gets a '​proxy'​ object for a component that provides all methods the component provides as fields, so they can be called more directly (instead of via `invoke`). This is what's used to generate '​primaries'​ of the individual component types, i.e. what you get via `component.blah`.  ​   Gets a '​proxy'​ object for a component that provides all methods the component provides as fields, so they can be called more directly (instead of via `invoke`). This is what's used to generate '​primaries'​ of the individual component types, i.e. what you get via `component.blah`.  ​
Line 25: Line 27:
 - `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 40: Line 36:
 print(rs0 == rs1) -- true print(rs0 == rs1) -- true
 ``` ```
 +
 +
 Contents Contents
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}