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.tmpAddress(): string
computer.freeMemory(): number
computer.totalMemory(): number
computer.energy(): number
computer.maxEnergy(): number
computer.uptime(): number
computer.shutdown([reboot: boolean])
reboot
is true, i.e. shuts down, then starts it again automatically. This function never returns.
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
computer.getBootAddress():string
computer.setBootAddress([address:string])
computer.runlevel(): string|number
Returns the current runlevel the computer is in. Current Runlevels in OpenOS are:
S
: Single-User mode, no components or filesystems initialized yet1
: Single-User mode, filesystems and components initialized - OpenOS finished bootingcomputer.users(): string, ...
table.pack
on it, first.
Please see the user rights documentation.computer.addUser(name: string): boolean or nil, string
true
if the user was successfully added. Returns nil
and an error message otherwise.useradd USER
is a command line option to invoke this method.computer.removeUser(name: string): boolean
true
if the user was removed, false
if they weren't registered in the first place.userdel USER
is a command line option to invoke this method.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 event type.
Generally it is more convenient to use event.pull
from the event library. The return value is the very same, but the event
library provides some more options.
computer.beep([frequency:string or number[, duration: number])
if frequency
is a number it value must be between 20 and 2000.
Causes the computer to produce a beep sound at frequency
Hz for duration
seconds. This method is overloaded taking a single string parameter as a pattern of dots .
and dashes -
for short and long beeps respectively.
computer.getDeviceInfo(): table
Returns a table of information about installed devices in the computer.