Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Completed merge of peripheral maps to their actual item/block pages. (+1 usability))
(Console -> Computer)
Line 1: Line 1:
 
The Peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the [[Disk Drive]], the [[Advanced Monitor]] and [[Monitor]].<br />
 
The Peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the [[Disk Drive]], the [[Advanced Monitor]] and [[Monitor]].<br />
[[Console|Consoles]] 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==
 
==Methods==
Line 50: Line 50:
  
 
==Computers==
 
==Computers==
[[Console#Peripheral_Functions|Computer Peripheral functions]] have been moved to the [[Computer]] page.
+
[[Computer#Peripheral_Functions|Computer Peripheral functions]] have been moved to the [[Computer]] page.
 
In addition, the [[Advanced_Computer#Peripheral_Functions|Advanced Computer Peripheral functions]] have been moved to the [[Advanced Computer]] page.
 
In addition, the [[Advanced_Computer#Peripheral_Functions|Advanced Computer Peripheral functions]] have been moved to the [[Advanced Computer]] page.
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 18:42, 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.

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 from that peripheral, as if calling peripheral.call(), e.g.:

m = peripheral.wrap("left")
m.someMethod()
- is the same as -
peripheral.call("left","someMethod")

Events

Event name Description Parameters
peripheral Fired when peripheral is attached side
peripheral_detach Fired when peripheral is removed side

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.