1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-26 01:50:29 +00:00

Small documentation improvements

- Document that settings.set doesn't persist values. I think this
   closes #1512 - haven't heard back from them.

 - Add missing close reasons to the websocket_closed event. Closes #1493.

 - Mention what values are preserved by os.queueEvent. This is just the
   same as modem.transmit. Closes #1490.
This commit is contained in:
Jonathan Coates 2023-07-06 23:03:22 +01:00
parent cab9c9772a
commit cc8c1f38e7
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
3 changed files with 50 additions and 15 deletions

View File

@ -13,6 +13,15 @@ The @{websocket_closed} event is fired when an open WebSocket connection is clos
## Return Values ## Return Values
1. @{string}: The event name. 1. @{string}: The event name.
2. @{string}: The URL of the WebSocket that was closed. 2. @{string}: The URL of the WebSocket that was closed.
3. <span class="type">@{string}|@{nil}</span>: The [server-provided reason][close_reason]
the websocket was closed. This will be @{nil} if the connection was closed
abnormally.
4. <span class="type">@{number}|@{nil}</span>: The [connection close code][close_code],
indicating why the socket was closed. This will be @{nil} if the connection
was closed abnormally.
[close_reason]: https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.6 "The WebSocket Connection Close Reason, RFC 6455"
[close_code]: https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5 "The WebSocket Connection Close Code, RFC 6455"
## Example ## Example
Prints a message when a WebSocket is closed (this may take a minute): Prints a message when a WebSocket is closed (this may take a minute):

View File

@ -132,7 +132,8 @@ public class OSAPI implements ILuaAPI {
* @param name The name of the event to queue. * @param name The name of the event to queue.
* @param args The parameters of the event. * @param args The parameters of the event.
* @cc.tparam string name The name of the event to queue. * @cc.tparam string name The name of the event to queue.
* @cc.param ... The parameters of the event. * @cc.param ... The parameters of the event. These can be any primitive type (boolean, number, string) as well as
* tables. Other types (like functions), as well as metatables, will not be preserved.
* @cc.see os.pullEvent To pull the event queued * @cc.see os.pullEvent To pull the event queued
*/ */
@LuaFunction @LuaFunction

View File

@ -2,13 +2,32 @@
-- --
-- SPDX-License-Identifier: LicenseRef-CCPL -- SPDX-License-Identifier: LicenseRef-CCPL
--- Read and write configuration options for CraftOS and your programs. --[[- Read and write configuration options for CraftOS and your programs.
--
-- By default, the settings API will load its configuration from the When a computer starts, it reads the current value of settings from the
-- `/.settings` file. One can then use @{settings.save} to update the file. `/.settings` file. These values then may be @{settings.get|read} or
-- @{settings.set|modified}.
-- @module settings
-- @since 1.78 :::caution
Calling @{settings.set} does _not_ update the settings file by default. You
_must_ call @{settings.save} to persist values.
:::
@module settings
@since 1.78
@usage Define an basic setting `123` and read its value.
settings.define("my.setting", {
description = "An example setting",
default = 123,
type = number,
})
print("my.setting = " .. settings.get("my.setting")) -- 123
You can then use the `set` program to change its value (e.g. `set my.setting 456`),
and then re-run the `example` program to check it has changed.
]]
local expect = dofile("rom/modules/main/cc/expect.lua") local expect = dofile("rom/modules/main/cc/expect.lua")
local type, expect, field = type, expect.expect, expect.field local type, expect, field = type, expect.expect, expect.field
@ -92,13 +111,19 @@ local function set_value(name, new)
end end
end end
--- Set the value of a setting. --[[- Set the value of a setting.
--
-- @tparam string name The name of the setting to set :::caution
-- @param value The setting's value. This cannot be `nil`, and must be Calling @{settings.set} does _not_ update the settings file by default. You
-- serialisable by @{textutils.serialize}. _must_ call @{settings.save} to persist values.
-- @throws If this value cannot be serialised :::
-- @see settings.unset
@tparam string name The name of the setting to set
@param value The setting's value. This cannot be `nil`, and must be
serialisable by @{textutils.serialize}.
@throws If this value cannot be serialised
@see settings.unset
]]
function set(name, value) function set(name, value)
expect(1, name, "string") expect(1, name, "string")
expect(2, value, "number", "string", "boolean", "table") expect(2, value, "number", "string", "boolean", "table")