peripheral

The Peripheral API is for interacting with peripherals connected to the computer, such as the Disk Drive, the Advanced Monitor and Monitor.

Each peripheral block has a name, either referring to the side the peripheral can be found on, or a name on an adjacent wired network.

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.

getNames()Provides a list of all peripherals available.
isPresent(name)Determines if a peripheral is present with the given name.
getType(peripheral)Get the type of a wrapped peripheral, or a peripheral with the given name.
getMethods(name)Get all available methods for the peripheral with the given name.
getName(peripheral)Get the name of a peripheral wrapped with peripheral.wrap.
call(name, method, ...)Call a method on the peripheral with the given name.
wrap(name)Get a table containing functions pointing to the peripheral's methods, which can then be called as if using peripheral.call.
find(ty[, filter])Find all peripherals of a specific type, and return the wrapped peripherals.
getNames()Source

Provides a list of all peripherals available.

If a device is located directly next to the system, then its name will be listed as the side it is attached to. If a device is attached via a Wired Modem, then it'll be reported according to its name on the wired network.

Returns

  1. { string... } A list of the names of all attached peripherals.
isPresent(name)Source

Determines if a peripheral is present with the given name.

Parameters

  1. name string The side or network name that you want to check.

Returns

  1. boolean If a peripheral is present with the given name.

Usage

getType(peripheral)Source

Get the type of a wrapped peripheral, or a peripheral with the given name.

Parameters

  1. peripheral string | table The name of the peripheral to find, or a wrapped peripheral instance.

Returns

  1. string | nil The peripheral's type, or nil if it is not present.
getMethods(name)Source

Get all available methods for the peripheral with the given name.

Parameters

  1. name string The name of the peripheral to find.

Returns

  1. { string... } | nil A list of methods provided by this peripheral, or nil if it is not present.
getName(peripheral)Source

Get the name of a peripheral wrapped with peripheral.wrap.

Parameters

  1. peripheral table The peripheral to get the name of.

Returns

  1. string The name of the given peripheral.
call(name, method, ...)Source

Call a method on the peripheral with the given name.

Parameters

  1. name string The name of the peripheral to invoke the method on.
  2. method string The name of the method
  3. ... Additional arguments to pass to the method

Returns

  1. The return values of the peripheral method.

Usage

  • Open the modem on the top of this computer.

    peripheral.call("top", "open", 1)
wrap(name)Source

Get a table containing functions pointing to the peripheral's methods, which can then be called as if using peripheral.call.

Parameters

  1. name string The name of the peripheral to wrap.

Returns

  1. table | nil The table containing the peripheral's methods, or nil if there is no peripheral present with the given name.

Usage

find(ty[, filter])Source

Find all peripherals of a specific type, and return the wrapped peripherals.

Parameters

  1. ty string The type of peripheral to look for.
  2. filter? function(name: string, wrapped: table):boolean A filter function, which takes the peripheral's name and wrapped table and returns if it should be included in the result.

Returns

  1. table... 0 or more wrapped peripherals matching the given filters.

Usage