此API主要提供了关于正在运行Lua state的电脑的信息,例如其地址和运行时间。API中还包含了用于用户管理的函数。此API中的函数可以从属于osAPI,但是为了保持“整洁”,这些函数归类为单独的API。
computer.tmpAddress(): stringcomputer.freeMemory(): numbercomputer.totalMemory(): numbercomputer.energy(): numbercomputer.maxEnergy(): numbercomputer.uptime(): numbercomputer.shutdown([reboot: boolean])reboot为true也可以重启电脑,重启即先关机再自动启动。此函数不会有返回值。local computer = require("computer") if computer.uptime() >= 300 then computer.shutdown(true) end
computer.getBootAddress():stringcomputer.setBootAddress([address:string])nil/不传参调用以清除。S: 单用户模式,组件和文件系统尚未初始化。1: 单用户模式,文件系统与组件已初始化——OpenOS完成了启动。computer.users(): string, ...table.pack。computer.addUser(name: string): boolean or nil, stringtrue,否则返回nil和一条报错信息。useradd <用户名>命令调用此方法。computer.removeUser(name: string): booleantrue,若用户先前未被登记则返回false。userdel <用户名>调用此方法。computer.pushSignal(name: string[, ...])nil、boolean、number、string和table。表(table)类型确实受支持(请继续读),但是线程和函数型变量不受支持。string型和number型,甚至可以是子表。但是不可以包含线程和数组。computer.pullSignal([timeout: number]): name, ...nil。如果不指定时间则永久等待。pushSignal推送的内容有关。依事件类型而定。
通常而言使用event库中的event.pull函数更加方便。返回值完全一致,但是event库提供了更多选项。computer.beep([frequency:string or number[, duration: number])frequency为数字,其值需要介于20与2000之间。frequency Hz,时长为duration秒的滴声。此函数已经被重载为可以接收字符串参数,其格式为点.与-破折号的组合,分别代表短与长滴声。computer.getDeviceInfo(): table