此API主要提供了关于正在运行Lua state的电脑的信息,例如其地址和运行时间。API中还包含了用于用户管理的函数。此API中的函数可以从属于os
API,但是为了保持“整洁”,这些函数归类为单独的API。
computer.tmpAddress(): string
computer.freeMemory(): number
computer.totalMemory(): number
computer.energy(): number
computer.maxEnergy(): number
computer.uptime(): number
computer.shutdown([reboot: boolean])
reboot
为true
也可以重启电脑,即先关机再自动启动。此函数不会有返回值。
下面的样例将会在电脑运行至少300秒(5分钟)后重启电脑。local computer = require("computer") if computer.uptime() >= 300 then computer.shutdown(true) end
computer.getBootAddress():string
computer.setBootAddress([address:string])
computer.runlevel(): string|number
返回电脑当前所在的运行状态(英文维基百科)。OpenOS的运行状态有:
S
: 单用户模式,尚未有组件或文件系统初始化1
: 单用户模式,文件系统与组件已初始化——OpenOS完成了启动computer.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.