Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Console -> Computer)
(Updated to API overview v2)
Line 2: Line 2:
 
[[Computer|Computers]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''.
 
[[Computer|Computers]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''.
  
==Methods==
+
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
{| class="wikitable"
+
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
!style="background:#EEE" width="210px"|Method name
+
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
!style="background:#EEE" width="*"|Description
+
Peripheral (API)
|-
+
</td></tr>
|[[peripheral.isPresent]](side)
+
 
|Returns '''true''' if a peripheral is present on ''side''.
+
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
|-
+
 
|[[peripheral.getType]](side)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[peripheral.isPresent]](side)</td>
|Returns the type or peripheral present on ''side'', nothing returned if ''side'' is empty.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns '''true''' if a peripheral is present on ''side''.</td></tr>
|-
+
 
|[[peripheral.getMethods]](side)
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[peripheral.getType]](side)</td>
|Returns a table containing all methods for peripheral on ''side''.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the type or peripheral present on ''side'', nothing returned if ''side'' is empty.</td></tr>
|-
+
 
|[[peripheral.call]](side, methodName, param1, param2, ...)
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[peripheral.getMethods]](side)</td>
|Sends a function call to peripheral located on ''side''. Return values match those of called method.<br />
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a table containing all methods for peripheral on ''side''.</td></tr>
'''Note:''' ''methodName'' is a string.
+
 
|-
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[peripheral.call]](side, methodName, param1, param2, ...)</td>
|[[peripheral.wrap]](side)
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a function call to peripheral located on ''side''. Return values match those of called method.<br />'''Note:''' ''methodName'' is a string.</td></tr>
|Returns a handle to the peripheral located on ''side''. If assigned to a variable, it can be used to call all methods available from that peripheral, as if calling '''peripheral.call()''', e.g.:<br />
+
 
m = [[peripheral.wrap]]("left")<br />
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[peripheral.wrap]](side)</td>
m.someMethod()<br />
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a handle to the peripheral located on ''side''. If assigned to a variable, it can be used to call all methods available from that peripheral, as if calling '''peripheral.call()''', e.g.:<br />m = [[peripheral.wrap]]("left")<br />m.someMethod()<br />''- is the same as -''<br />[[peripheral.call]]("left","someMethod")</td></tr>
''- is the same as -''<br />
+
 
[[peripheral.call]]("left","someMethod")
+
</table>
|}
+
 
 +
 
 +
[[Category:APIs]]
  
==Events==
 
{| class="wikitable"
 
!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
 
|}
 
 
==Monitor==
 
==Monitor==
 
[[Monitor#Peripheral_Functions|Monitor Peripheral functions]] have been moved to the [[Monitor]] page.
 
[[Monitor#Peripheral_Functions|Monitor Peripheral functions]] have been moved to the [[Monitor]] page.

Revision as of 22:23, 30 November 2012

The Peripheral API is for interacting with external peripherals, such as the Disk Drive, the Advanced Monitor and Monitor.
Computers and Turtles are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to rednet. Both Computers and Turtles provide the same methods: turnOn, shutdown, reboot, getID.

Grid disk.png   Peripheral (API)

Method NameDescription
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 from that peripheral, as if calling peripheral.call(), e.g.:
m = peripheral.wrap("left")
m.someMethod()
- is the same as -
peripheral.call("left","someMethod")

Monitor

Monitor Peripheral functions have been moved to the Monitor page. In addition, the Advanced Monitor Peripheral functions have been moved to the Advanced Monitor page.

Printer

Printer Peripheral functions have been moved to the Printerpage.

Computers

Computer Peripheral functions have been moved to the Computer page. In addition, the Advanced Computer Peripheral functions have been moved to the Advanced Computer page.