diff --git a/doc/events/websocket_closed.md b/doc/events/websocket_closed.md index 06a991fa8..c6870258b 100644 --- a/doc/events/websocket_closed.md +++ b/doc/events/websocket_closed.md @@ -13,6 +13,15 @@ ## Return Values 1. @{string}: The event name. 2. @{string}: The URL of the WebSocket that was closed. +3. @{string}|@{nil}: The [server-provided reason][close_reason] + the websocket was closed. This will be @{nil} if the connection was closed + abnormally. +4. @{number}|@{nil}: 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 Prints a message when a WebSocket is closed (this may take a minute): diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/OSAPI.java b/projects/core/src/main/java/dan200/computercraft/core/apis/OSAPI.java index 0d2e2347f..86b395e9b 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/OSAPI.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/OSAPI.java @@ -132,7 +132,8 @@ private static long getEpochForCalendar(Calendar c) { * @param name The name of the event to queue. * @param args The parameters of the event. * @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 */ @LuaFunction diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/settings.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/settings.lua index e4ebd7cff..d1481401b 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/settings.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/settings.lua @@ -2,13 +2,32 @@ -- -- SPDX-License-Identifier: LicenseRef-CCPL ---- Read and write configuration options for CraftOS and your programs. --- --- By default, the settings API will load its configuration from the --- `/.settings` file. One can then use @{settings.save} to update the file. --- --- @module settings --- @since 1.78 +--[[- Read and write configuration options for CraftOS and your programs. + +When a computer starts, it reads the current value of settings from the +`/.settings` file. These values then may be @{settings.get|read} or +@{settings.set|modified}. + +:::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 type, expect, field = type, expect.expect, expect.field @@ -92,13 +111,19 @@ local function set_value(name, new) end end ---- Set the value of a setting. --- --- @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 +--[[- Set the value of a setting. + +:::caution +Calling @{settings.set} does _not_ update the settings file by default. You +_must_ call @{settings.save} to persist values. +::: + +@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) expect(1, name, "string") expect(2, value, "number", "string", "boolean", "table")