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.romAddress(): string
computer.tmpAddress(): string
computer.freeMemory(): number
computer.totalMemory(): number
computer.energy(): number
computer.maxEnergy(): number
computer.isRobot(): boolean
dig
program. Deprecated: This method is deprecated, it was removed in OC 1.3. Use component.isAvailable("robot")
instead.computer.uptime(): number
computer.shutdown([reboot: boolean])
reboot
is true, i.e. shuts down, then starts it again automatically. This function never returns.computer.getBootAddress():string
computer.setBootAddress([address:string])
computer.users(): string, ...
table.pack
on it, first.computer.addUser(name: string): boolean or nil, string
true
if the user was successfully added. Returns nil
and an error message otherwise.computer.removeUser(name: string): boolean
true
if the user was removed, false
if they weren't registered in the first place.computer.pushSignal(name: string[, ...])
computer.pullSignal([timeout: number]): name, ...
nil
. If no timeout is specified waits forever.pushSignal
, for example. These vary based on the even type.event.pull
to wait for events, as opposed to calling this directly. Using event.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)
lua
local computer = require("computer")
if computer.uptime() >= 300 then
computer.shutdown(true)
end
Contents