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
component:component_access [2014/12/25 20:56]
vexatos
component:component_access [2018/11/27 14:59] (current)
krakodeel [Addresses]
Line 5: Line 5:
 Addresses Addresses
 --------- ---------
-Components all have an address. This address is a UUID, a unique identifier. In most cases it is OK to abbreviate these addresses. For example to get the full address from an abbreviated one you can use `component.get`. To get the address of any block in particular, you can use the [[:​analyzer|Analyzer]] by holding the control key while right clicking the block.+Components all have an address. This address is a UUID, a unique identifier. In most cases it is OK to abbreviate these addresses. For example to get the full address from an abbreviated one you can use `component.get`. To get the address of any block in particular, you can use the [[item:​analyzer|Analyzer]] by holding the control key while right clicking the block.
  
 To get a list of all components attached to your computer you can do this: To get a list of all components attached to your computer you can do this:
Line 19: Line 19:
  
 Note that item components will usually keep their address even when removed from a computer. So when removing a hard drive and inserting it back in, it will have the same address as before. This is *not* the case for block components, they will always get a new address after being broken and placed again. Note that item components will usually keep their address even when removed from a computer. So when removing a hard drive and inserting it back in, it will have the same address as before. This is *not* the case for block components, they will always get a new address after being broken and placed again.
 +
 +Optionally you can filter components list like this:
 +
 +This code will add every component which name contains "​adar"​ such as computronics radar or warpDrive radar to the local radars table
 +```lua
 +local component = require("​component"​)
 +local radars = {}
 +for address, name in component.list("​adar",​ false) do
 +  table.insert(radars,​ component.proxy(address))
 +end
 +```
 +
 +This code will add all connected warpDrive radars only to the local radars table
 +```lua
 +local component = require("​component"​)
 +local radars = {}
 +for address, name in component.list("​warpdriveRadar",​ true) do
 +  table.insert(radars,​ component.proxy(address))
 +end
 +```
  
 Primary Components Primary Components
Line 40: Line 60:
 ``` ```
  
-The usually ​preferred way will usually be to get a proxy, however. A proxy is simply a table that provides one function for each API callback, named after that callback. In addition, each proxy has two fields: `address`, which holds the address of the wrapped component, and `type`, which holds the type of the component. You can get a proxy like this:+The preferred way will usually be to get a proxy, however. A proxy is simply a table that provides one function for each API callback, named after that callback. In addition, each proxy has two fields: `address`, which holds the address of the wrapped component, and `type`, which holds the type of the component. You can get a proxy like this:
 ```lua ```lua
 local component = require("​component"​) local component = require("​component"​)
Line 57: Line 77:
 Direct Calls Direct Calls
 ------------ ------------
-Some component callbacks can performed as "​direct calls"​. Direct calls are performed in the computer'​s worker thread, meaning they will return instantly. Normal calls are delegated to the main server thread, to avoid race conditions and other threading issues, which also means that normal calls will take up to one tick (i.e. 50 ms). Just to be clear: this only applies to component APIs.+Some component callbacks can be performed as "​direct calls"​. Direct calls are performed in the computer'​s worker thread, meaning they will return instantly. Normal calls are delegated to the main server thread, to avoid race conditions and other threading issues, which also means that normal calls will take up to one tick (i.e. 50 ms). Just to be clear: this only applies to component APIs.
  
 Signals Signals