Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:computer:zh [2022/08/11 10:01]
fight_xing
api:computer:zh [2023/11/29 11:16] (current)
hfsr [Computer(电脑) API]
Line 1: Line 1:
-Computer API+Computer(电脑) ​API
 =========== ===========
- +此API主要提供了关于正在运行Lua state电脑的信息,例如其地址和运时间。API中还包含了用于用户管理的函数。此API中的函数可以从属于`os`API,但是为了保持“整洁”,这些函数归类为单独的API。
-**本篇文章部分/​全部内容还没有进翻译** +
- +
-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`  ​ - `computer.address():​ string`  ​
-  ​The [[:​component:​component_access|component address]] of this computer.+  ​此电脑的[[:​component:​component_access:zh|组件地址]]。   
 +\\
 - `computer.tmpAddress():​ string`  ​ - `computer.tmpAddress():​ string`  ​
-  ​The component address of the computer'​s temporary file system (if any), used for mounting it on startup.+  ​此电脑的临时文件系统组件地址(如果有),用于在启动时挂载此文件系统。 ​  
 +\\
 - `computer.freeMemory():​ number`  ​ - `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. Note that for OpenOS, it is highly recommended to at least have 1x tier 1.5 RAM stick or more. The os will boot on a single tier ram stick, but quickly and easily run out of memory.+  ​当前未使用的内存大小,单位为字节。如果此数值接近0,那么你的电脑可能会很快因为内存不足而崩溃(报出“out of memory”错误)。请注意,为了运行OpenOS,高度建议用户安装1条或以上1.5级内存条。系统能用单条1级内存启动,但很快就容易内存不足。 ​  
 +\\
 - `computer.totalMemory():​ number`  ​ - `computer.totalMemory():​ number`  ​
-  ​The total amount of memory installed in this computer, in bytes.+  ​此电脑安装的内存总量,单位为字节。 ​  
 +\\
 - `computer.energy():​ number`  ​ - `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`  ​ - `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).+  ​电脑所在网络中能够存储的最大能量数量。对机器人而言是机器人的内置能量缓存大小(可以在机器人的GUI中查看)。 ​  
 +\\
 - `computer.uptime():​ number`  ​ - `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])`  ​ - `computer.shutdown([reboot:​ boolean])`  ​
-  ​Shuts down the computer. Optionally reboots the computer, if `reboot` ​is true, i.e. shuts down, then starts it again automatically. This function never returns. +  ​关闭电脑。如果`reboot`为`true`也可以重启电脑,重启即先关机再自动启动。此函数不会有返回值。  ​ 
-  ​This example will reboot the computer if it has been running for at least 300 seconds(minutes)+  ​下面的样例将会在电脑运行至少300秒(5分钟)后重启电脑。
  
 ```lua ```lua
Line 32: Line 36:
  
 - `computer.getBootAddress():​string`  ​ - `computer.getBootAddress():​string`  ​
-  ​Get the address of the filesystem component from which to try to boot first. ​*New since OC 1.3*.+  ​获取首先尝试用于引导启动的文件系统组件地址。 ​  
 +**OC 1.3新加入。**   
 +\\
 - `computer.setBootAddress([address:​string])`  ​ - `computer.setBootAddress([address:​string])`  ​
-  ​Set the address of the filesystem component from which to try to boot first. Call with nil / no arguments to clear. ​*New since OC 1.3*. +  ​设定首先尝试用于引导启动的文件系统组件地址。传参`nil`/不传参调用以清除。 ​  
-- `computer.runlevel():​ string|number` +**OC 1.3新加入。**   
- +\\ 
-  ​Returns the current ​[[https://​en.wikipedia.org/​wiki/​Runlevel|runlevel]] ​the computer is in. Current Runlevels in OpenOS ​are: +- `computer.runlevel():​ string|number` ​  
-  - `S`: Single-User mode, no components or filesystems initialized yet +  ​返回电脑当前所在的[[https://​en.wikipedia.org/​wiki/​Runlevel|运行级别(runlevel]](英文维基百科)。OpenOS的运行级别有: 
-  - `1`: Single-User mode, filesystems and components initialized - OpenOS ​finished booting+  - `S`: 单用户模式,组件和文件系统尚未初始化。 
 +  - `1`: 单用户模式,文件系统与组件已初始化——OpenOS完成了启动。 ​  
 +\\
 - `computer.users():​ string, ...`  ​ - `computer.users():​ string, ...`  ​
-  ​A list of all users registered on this computer, as a tuple. To iterate the result as a list, use `table.pack` ​on it, first. +  ​此电脑上的全体登记用户列表,形式为元组(tuple)。若要将结果转化为表,请先对其使用`table.pack`。  ​ 
-  ​Please see [[:​computer_users|the user rights documentation]].+  ​请参见[[:​computer_users:zh|用户行为控制文档]]获取更多信息。 ​  
 +\\
 - `computer.addUser(name:​ string): boolean or nil, string`  ​ - `computer.addUser(name:​ string): boolean or nil, string`  ​
-  ​Registers a new user with this computer. Returns ​`true` ​if the user was successfully added. Returns ​`nil` and an error message otherwise. ​  +  ​在此电脑上登记一个新用户。若添加成功则返回`true`,否则返回`nil`和一条报错信息。 ​  
-  ​The user must be currently in the game. The user will gain full access rights on the computer. In the shell`useradd ​USERis a command line option to invoke this method.+  ​欲添加的用户必须在游戏中。此用户将会获得此电脑的完全访问权限。在shell中,可以执行`useradd ​<​用户名>​`命令调用此方法。 ​  
 +\\
 - `computer.removeUser(name:​ string): boolean`  ​ - `computer.removeUser(name:​ string): boolean`  ​
-  ​Unregisters a user from this computer. Returns ​`true` ​if the user was removed, ​`false` ​if they weren'​t registered in the first place. ​  +  ​删除此电脑上的某个用户。若用户成功被移除则返回`true`,若用户先前未被登记则返回`false`。   
-  ​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. ​`userdel ​USERis a command line option to invoke this method.+  ​此用户将会失去对此电脑的一切访问权限。当用户列表中的所有用户均被移除时,任何用户均可访问此电脑。在命令行中可使用`userdel ​<​用户名>​`调用此方法。 ​  
 +\\
 - `computer.pushSignal(name:​ string[, ...])`  ​ - `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 nilbooleannumberstring, and tables. Yes tables are supported (keep reading). Threads and functions are not supported. +  ​向队列中推送一个新信号。信号按照先进先出顺序处理。推送的信号应至少有信号名,是否存在一并传递的参数均可。请注意只有基本数据类型才可作为信号参数,包括:`nil`、`boolean`、`number`、`string`和`table`。表(table)类型确实受支持(请继续读),但是线程和函数型变量不受支持。 ​  
-   +  ​请注意只有特定类型的表才受支持。具体而言,表必须由受支持的数据类型组成,例如`string`型和`number`型,甚至可以是子表。但是不可以包含线程和数组。 ​  
-  ​Note that only tables of the supported types are supported. That is, tables must compose types supported, such as other strings and numbers, or even sub tables. But not of functions or threads.+\\
 - `computer.pullSignal([timeout:​ number]): name, ...`  ​ - `computer.pullSignal([timeout:​ number]): name, ...`  ​
-  ​Tries to pull a signal from the queue, waiting up to the specified amount of time before failing and returning ​`nil`. If no timeout is specified waits forever. ​  +  ​尝试从队列中拉取一个信号,在等待指定时长后判定为失败并返回`nil`。如果不指定时间则永久等待。 ​  
-  ​The first returned result is the signal name, following results correspond to what was pushed in `pushSignal`, for example. These vary based on the event type. +  ​返回结果的第一个值为信号名,后续返回值与`pushSignal`推送的内容有关。依事件类型而定。 
-  ​Generally it is more convenient to use `event.pull` from the [[api:​event|event]] ​libraryThe return value is the very same, but the `event` ​library provides some more options. +  ​通常而言使用[[api:event:zh|event]]库中的`event.pull`函数更加方便。返回值完全一致,但是`event`库提供了更多选项。  ​ 
- +\\ 
-- `computer.beep([frequency:​string or number[, duration: number])` +- `computer.beep([frequency:​string or number[, duration: number])` ​  
- +  ​`frequency`为数字,其值需要介于202000之间。  ​ 
-  ​if `frequency` ​is a number it value must be between ​20 and 2000+  ​让电脑产生频率为`frequency` Hz,时长为`duration`秒的滴声。此函数已经被重载为可以接收字符串参数,其格式为点`.``-`破折号的组合,分别代表短与长滴声。  ​ 
- +\\ 
-  ​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` ​  
- +  ​返回存储了此电脑上安装的设备信息的表。
-- `computer.getDeviceInfo():​ table` +
- +
-  ​Returns a table of information about installed devices in the computer.+
  
 目录 目录
 ----------- -----------
 {{page>​api:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}}