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 [2016/06/15 08:44]
payonel [Computer API]
api:computer [2021/04/23 15:04] (current)
heaven31415 [Computer API] Add information about the valid values of frequency for computer.beep() method
Line 19: Line 19:
 - `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.   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.
 +  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
 +```
 +
 - `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*.   Get the address of the filesystem component from which to try to boot first. *New since OC 1.3*.
Line 38: Line 47:
   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 USER` is a command line option to invoke this method.   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 USER` is a command line option to invoke this method.
 - `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 nil, boolean, number ​and string, tables and functions are not supported.+  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 nil, boolean, numberstring, ​and tables. Yes tables are supported (keep reading). Threads ​and functions are not supported
 +   
 +  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.  ​   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.  ​
-  The first returned result is the signal name, following results correspond to what was pushed in `pushSignal`,​ for example. These vary based on the even type. +  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. 
-  ​ +  ​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.
-  * **important**  ​it is generally advisable ​to use `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 event listeners which is required by some libraries to work correctly (e.g. the [[api:component|component]] 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)+- `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.
  
-```lua 
-local computer = require("​computer"​) 
-if computer.uptime() >= 300 then 
-    computer.shutdown(true) 
-end 
-``` 
-` 
 Contents Contents
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}