Difference between revisions of "Peripheral (API)"
From ComputerCraft Wiki
(Just adding a missing '.) |
|||
Line 1: | Line 1: | ||
The peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the disk drive and monitor. | The peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the disk drive and monitor. | ||
+ | [[Console|Consoles]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion, compared to with [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''. | ||
+ | |||
+ | ==Methods== | ||
{| border="1" cellpadding="2" cellspacing="0" | {| border="1" cellpadding="2" cellspacing="0" | ||
!style="background:#EEE" width="210px"|Method name | !style="background:#EEE" width="210px"|Method name | ||
!style="background:#EEE" width="*"|Description | !style="background:#EEE" width="*"|Description | ||
|- | |- | ||
− | |peripheral.isPresent( side ) | + | |[[peripheral.isPresent]]( side ) |
|Returns '''true''' if a peripheral is present on ''side''. | |Returns '''true''' if a peripheral is present on ''side''. | ||
|- | |- | ||
− | |peripheral.getType( side ) | + | |[[peripheral.getType]]( side ) |
|Returns the type or peripheral present on ''side'', nothing returned if ''side'' is empty. | |Returns the type or peripheral present on ''side'', nothing returned if ''side'' is empty. | ||
|- | |- | ||
− | |peripheral.getMethods( side ) | + | |[[peripheral.getMethods]]( side ) |
|Returns a table containing all methods for peripheral on ''side''. | |Returns a table containing all methods for peripheral on ''side''. | ||
|- | |- | ||
− | |peripheral.call( side, methodName, param1, param2, ... ) | + | |[[peripheral.call]]( side, methodName, param1, param2, ... ) |
|Sends a function call to peripheral located on ''side''. Return values match those of called method.<br /> | |Sends a function call to peripheral located on ''side''. Return values match those of called method.<br /> | ||
'''Note:''' ''methodName'' is a string. | '''Note:''' ''methodName'' is a string. | ||
|- | |- | ||
− | |peripheral.wrap( side ) | + | |[[peripheral.wrap]]( side ) |
|Returns a handle to the peripheral located on ''side''. If assigned to a variable, it can be used to call all methods available, as if calling '''peripheral.call()''', e.g.:<br /> | |Returns a handle to the peripheral located on ''side''. If assigned to a variable, it can be used to call all methods available, as if calling '''peripheral.call()''', e.g.:<br /> | ||
fdd = peripheral.wrap("left")<br /> | fdd = peripheral.wrap("left")<br /> | ||
Line 24: | Line 27: | ||
peripheral.call("left","isPresent") | peripheral.call("left","isPresent") | ||
|} | |} | ||
− | + | ||
+ | ==Events== | ||
+ | {| border="1" cellpadding="2" cellspacing="0" | ||
+ | !style="background:#EEE" width="210px"|Event name | ||
+ | !style="background:#EEE" width="*"|Description | ||
+ | !style="background:#EEE" width="*"|Parameters | ||
+ | |- | ||
+ | |peripheral | ||
+ | |Fired when peripheral is attached | ||
+ | |side | ||
+ | |- | ||
+ | |peripheral_detach | ||
+ | |Fired when peripheral is removed | ||
+ | |side | ||
+ | |} | ||
+ | |||
[[Category:APIs]] | [[Category:APIs]] |
Revision as of 19:36, 29 May 2012
The peripheral API is for interacting with external peripherals, such as the disk drive and monitor. Consoles and Turtles are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion, compared to with rednet. Both Computers and Turtles provide the same methods: turnOn, shutdown, reboot, getID.
Methods
Method name | Description |
---|---|
peripheral.isPresent( side ) | Returns true if a peripheral is present on side. |
peripheral.getType( side ) | Returns the type or peripheral present on side, nothing returned if side is empty. |
peripheral.getMethods( side ) | Returns a table containing all methods for peripheral on side. |
peripheral.call( side, methodName, param1, param2, ... ) | Sends a function call to peripheral located on side. Return values match those of called method. Note: methodName is a string. |
peripheral.wrap( side ) | Returns a handle to the peripheral located on side. If assigned to a variable, it can be used to call all methods available, as if calling peripheral.call(), e.g.: fdd = peripheral.wrap("left") |
Events
Event name | Description | Parameters |
---|---|---|
peripheral | Fired when peripheral is attached | side |
peripheral_detach | Fired when peripheral is removed | side |