-
Notifications
You must be signed in to change notification settings - Fork 434
API Computer
Vexatos edited this page Jul 13, 2014
·
6 revisions
For those that don't like images: the wiki has moved to a new place, http://ocdoc.cil.li/.
This wiki will no longer be updated.
This API mainly provides information about the computer a Lua state is running on, such as its address and uptime. It also contains functions for user management. This could belong to the os
table, but in order to keep that "clean" it's in its own API.
-
computer.address(): string
The component address of this computer. -
computer.romAddress(): string
The component address of the computer's ROM file system, used for mounting it on startup. -
computer.tmpAddress(): string
The component address of the computer's temporary file system (if any), used for mounting it on startup. -
computer.freeMemory(): number
The amount of memory currently unused, in bytes. If this gets close to zero your computer will probably soon crash with an out of memory error. -
computer.totalMemory(): number
The total amount of memory installed in this computer, in bytes. -
computer.energy(): number
The amount of energy currently available in the network the computer is in. For a robot this is the robot's own energy / fuel level. -
computer.maxEnergy(): number
The maximum amount of energy that can be stored in the network the computer is in. For a robot this is the size of the robot's internal buffer (what you see in the robot's GUI). -
computer.isRobot(): boolean
Whether this computer is a robot or not. Mostly useful to allow failing early in some programs, such as the built-inThis method is deprecated, it will be removed soon. Usedig
program.component.isAvailable("robot")
instead. -
computer.uptime(): number
The time in real world seconds this computer has been running, measured based on the world time that passed since it was started - meaning this will not increase while the game is paused, for example. -
computer.shutdown([reboot: boolean])
Shuts down the computer. Optionally reboots the computer, ifreboot
is true, i.e. shuts down, then starts it again automatically. This function never returns. -
computer.users(): string, ...
A list of all users registered on this computer, as a tuple. To iterate the result as a list, usetable.pack
on it, first.
Please see the user rights documentation. -
computer.addUser(name: string): boolean or nil, string
Registers a new user with this computer. Returnstrue
if the user was successfully added. Returnsnil
and an error message otherwise.
The user must be currently in the game. The user will gain full access rights on the computer. -
computer.removeUser(name: string): boolean
Unregisters a user from this computer. Returnstrue
if the user was removed,false
if they weren't registered in the first place.
The user will lose all access to this computer. When the last user is removed from the user list, the computer becomes accessible to all players. -
computer.pushSignal(name: string[, ...])
Pushes a new signal into the queue. Signals are processed in a FIFO order. The signal has to at least have a name. Arguments to pass along with it are optional. Note that the types supported as signal parameters are limited to the basic types nil, boolean, number and string, tables and functions are not supported. -
computer.pullSignal([timeout: number]): name, ...
Tries to pull a signal from the queue, waiting up to the specified amount of time before failing and returningnil
. If no timeout is specified waits forever.
The first returned result is the signal name, following results correspond to what was pushed inpushSignal
, for example. These vary based on the even type.
Important: it is generally advisable to useevent.pull
to wait for events, as opposed to calling this directly. Usingevent.pull
will ensure that any other signals arriving in the meantime will be distributed as events, which is required by some libraries to work correctly (e.g. the term API). It also provides more advanced filtering.
This example will reboot the computer if it has been running for at least 300 seconds(5 minutes)
local computer = require("computer")
if computer.uptime() >= 300 then
computer.shutdown(true)
end