Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Love Adding machine)
(Computers: Adding modems)
 
(51 intermediate revisions by 26 users not shown)
Line 1: Line 1:
I want to share in this area I initiate when looking for the benefit of discount auto parts, they saved me 100s of dollars when I was getting my car back on the motorway form month, so I thought I'd restore the karma and give them a do away with on here. On the whole 'mark-down auto parts' time out to be anything but, and you end up spending over-the-odds concerning in reduced circumstances grade parts and yeah, that's no longer a mistake I can provide to up, who can in this restraint, right? So, rpm-motots-inc.com are different, like extraordinarily, indeed different. Earliest up, the quotation you are quoted is the payment you satisfy, no cryptic extras. The parts I ordered were all in stock, were shipped stable and were fount packaged. I was amazed with the grade, predominantly for the weak price I paid, which was
+
{{msgbox
$391 cheaper than the popular diminish auto parts sites. I had a scarcely any questions in front I ordered and the crook I spoke to were bloody beneficial, and knew their stuff. Their customer handling and range of parts is stirring, rpm motors certainly nurture their promises when it comes to minimize auto parts.
+
| text = This article is about the Peripheral API. For APIs exposed when wrapping peripherals through [[peripheral.wrap]]() see [[:Category:Peripheral_APIs|Peripheral APIs]].
 +
}}
 +
 
 +
__TOC__
 +
The Peripheral API is for interacting with [[peripheral]]s connected to the computer, such as the [[Disk Drive]], the [[Advanced Monitor]] and [[Monitor]]. (More peripherals can be found under [[:Category:Peripherals|here]]).
 +
 
 +
Each peripheral block has a name, or ''side''. Although peripherals can now be attached to a computer using networking cables, the word ''side'' is a holdover from when peripherals needed to be directly next to the computer.
 +
 
 +
If the peripheral is next to the computer, its side is either "front", "back", "left", "right", "top" or "bottom". If the peripheral is attached by a cable, its side will follow the format "''type''_''id''", for example "printer_0".
 +
 
 +
Peripheral functions are called '''methods''', a term borrowed from Java.
 +
 
 +
{{API table|Peripheral|image=Grid disk.png|2=
 +
 
 +
{{API table/row|[[peripheral.isPresent]]({{type|string}} side)|{{type|boolean}}|
 +
Returns '''true''' if a peripheral is connected on ''side''.
 +
|odd}}
 +
 
 +
{{API table/row|[[peripheral.getType]]({{type|string}} side)|{{type|string}} /{{type|nil}}|
 +
Returns the type of peripheral connected on ''side'', as a string.
 +
If no peripheral is connected, returns nil.
 +
}}
 +
 
 +
{{API table/row|[[peripheral.getMethods]]({{type|string}} side)|{{type|table}} /{{type|nil}}|
 +
Returns a list of the names of all the methods of the peripheral connected on ''side''.
 +
If no peripheral is connected, returns nil.
 +
|odd}}
 +
 
 +
{{API table/row|[[peripheral.call]]({{type|string}} side, {{type|string}} method, ...)|any|
 +
Calls a method on a peripheral. The arguments (apart from ''side'' and ''method'') and the return values depend on the method being called.
 +
If no peripheral is connected, returns nil.
 +
}}
 +
 
 +
{{API table/row|[[peripheral.wrap]]({{type|string}} side)|{{type|table}} peripheral / {{type|nil}}|
 +
Returns a table of functions, allowing you to call peripheral methods as if they were normal Lua functions.
 +
If no peripheral is connected, returns nil.
 +
|odd}}
 +
 
 +
{{API table/row|[[peripheral.find]]({{type|string}} type [, {{type|function}} fnFilter( name, object )])|{{type|table}} peripheral / {{type|nil}}|
 +
Finds an attached peripheral of the given type and if found returns a table of functions, similar to [[peripheral.wrap]], allowing you to call peripheral methods as if they were normal Lua functions.
 +
If no peripheral of the given type is connected, it returns nil. '''''Requires ComputerCraft 1.6 or later.'''''
 +
|odd}}
 +
 
 +
{{API table/row|[[peripheral.getNames]]()|{{type|table}}|
 +
This function returns a table of all the sides that have a peripheral present. If the present peripheral is a wired modem any names of the peripherals that is on the network are also added to the table.
 +
|odd}}
 +
 
 +
}}
 +
 
 +
==Connecting peripherals using networking cables==
 +
Using Networking Cables, you can attach and use peripherals without having them directly touching the computer. To connect a peripheral in this way, place a Wired Modem on any side of your computer, as you would a [[Wireless Modem]]. Place a Wired Modem on each peripheral you wish to connect, and then connect all of them with Networking Cables. Then right click each of the wired modems.
 +
 
 +
You should receive a message in your chat bar for each peripheral informing you of a successful connection, and the peripheral side.
 +
 
 +
==Monitor==
 +
[[Monitor]] and [[Advanced Monitor]] peripheral functions can be found on the [[Term (API)]] page. Note that the [[Colors (API)|Colors API]] can also be useful for designing colors for use on an advanced monitor.
 +
 
 +
==Printer==
 +
[[Printer#Printer API |Printer Peripheral functions]] have been moved to the [[Printer]] page.
 +
 
 +
==Computers==
 +
[[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.
 +
 
 +
==Modem==
 +
[[Modem]] peripheral functions can be found on the [[Modem (API)]] page.
 +
 
 +
[[Category:APIs]]

Latest revision as of 04:06, 9 November 2014

This article is about the Peripheral API. For APIs exposed when wrapping peripherals through peripheral.wrap() see Peripheral APIs.

The Peripheral API is for interacting with peripherals connected to the computer, such as the Disk Drive, the Advanced Monitor and Monitor. (More peripherals can be found under here).

Each peripheral block has a name, or side. Although peripherals can now be attached to a computer using networking cables, the word side is a holdover from when peripherals needed to be directly next to the computer.

If the peripheral is next to the computer, its side is either "front", "back", "left", "right", "top" or "bottom". If the peripheral is attached by a cable, its side will follow the format "type_id", for example "printer_0".

Peripheral functions are called methods, a term borrowed from Java.

Grid disk.png  Peripheral (API)
Function Return values Description
peripheral.isPresent(string side) boolean

Returns true if a peripheral is connected on side.

peripheral.getType(string side) string /nil

Returns the type of peripheral connected on side, as a string. If no peripheral is connected, returns nil.

peripheral.getMethods(string side) table /nil

Returns a list of the names of all the methods of the peripheral connected on side. If no peripheral is connected, returns nil.

peripheral.call(string side, string method, ...) any

Calls a method on a peripheral. The arguments (apart from side and method) and the return values depend on the method being called. If no peripheral is connected, returns nil.

peripheral.wrap(string side) table peripheral / nil

Returns a table of functions, allowing you to call peripheral methods as if they were normal Lua functions. If no peripheral is connected, returns nil.

peripheral.find(string type [, function fnFilter( name, object )]) table peripheral / nil

Finds an attached peripheral of the given type and if found returns a table of functions, similar to peripheral.wrap, allowing you to call peripheral methods as if they were normal Lua functions. If no peripheral of the given type is connected, it returns nil. Requires ComputerCraft 1.6 or later.

peripheral.getNames() table

This function returns a table of all the sides that have a peripheral present. If the present peripheral is a wired modem any names of the peripherals that is on the network are also added to the table.

Connecting peripherals using networking cables

Using Networking Cables, you can attach and use peripherals without having them directly touching the computer. To connect a peripheral in this way, place a Wired Modem on any side of your computer, as you would a Wireless Modem. Place a Wired Modem on each peripheral you wish to connect, and then connect all of them with Networking Cables. Then right click each of the wired modems.

You should receive a message in your chat bar for each peripheral informing you of a successful connection, and the peripheral side.

Monitor

Monitor and Advanced Monitor peripheral functions can be found on the Term (API) page. Note that the Colors API can also be useful for designing colors for use on an advanced monitor.

Printer

Printer Peripheral functions have been moved to the Printer page.

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.

Modem

Modem peripheral functions can be found on the Modem (API) page.