diff --git a/.gitattributes b/.gitattributes index dd61639..40fe381 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,6 +16,7 @@ # Generated or vendored content: collapsed in diffs, excluded from language stats. third_party/lua52/dist/** linguist-generated=true data/eeex/**.json linguist-generated=true +data/lua52/**.json linguist-generated=true package-lock.json linguist-generated=true -diff # Third-party upstream sources. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c4dd44..8299b1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ # - One Linux runner per job; jobs that only matter for some paths are skipped # by the `changes` job (workflow-level `paths:` filters are not used because a # skipped workflow never reports, which blocks required status checks). -# - npm, VS Code test builds and emsdk are cached. +# - npm, VS Code test builds, emsdk and the Lua source tarball are cached. # - Superseded pull request runs are cancelled. # Failures are reported as file/line annotations (setup-node's tsc and ESLint # problem matchers, and `::error` lines from scripts/). @@ -33,6 +33,7 @@ jobs: outputs: code: ${{ steps.diff.outputs.code }} wasm: ${{ steps.diff.outputs.wasm }} + manual: ${{ steps.diff.outputs.manual }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -49,6 +50,7 @@ jobs: echo "No usable base commit; running every job." echo "code=true" >> "$GITHUB_OUTPUT" echo "wasm=true" >> "$GITHUB_OUTPUT" + echo "manual=true" >> "$GITHUB_OUTPUT" exit 0 fi changed="$(git diff --name-only "$BASE" HEAD)" @@ -64,6 +66,11 @@ jobs: else echo "wasm=false" >> "$GITHUB_OUTPUT" fi + if printf '%s\n' "$changed" | grep -qE '^(scripts/lua-manual/|data/lua52/|third_party/lua52/tarball\.mts$|\.github/workflows/ci\.yml$)'; then + echo "manual=true" >> "$GITHUB_OUTPUT" + else + echo "manual=false" >> "$GITHUB_OUTPUT" + fi checks: name: Type-check, lint, unit tests, package @@ -191,13 +198,17 @@ jobs: exit 1 fi echo "version=$version" >> "$GITHUB_OUTPUT" - - name: Cache emsdk and Lua sources + - name: Cache emsdk uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - .cache/emsdk - .cache/lua + path: .cache/emsdk key: emsdk-${{ runner.os }}-${{ steps.emsdk.outputs.version }} + # Shared with the `manual` job; the key changes when the pinned tarball does. + - name: Cache the Lua source tarball + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: .cache/lua + key: lua-src-${{ hashFiles('third_party/lua52/tarball.mts') }} - name: Install emsdk ${{ steps.emsdk.outputs.version }} env: VERSION: ${{ steps.emsdk.outputs.version }} @@ -211,3 +222,25 @@ jobs: run: | source .cache/emsdk/emsdk_env.sh npm run build:wasm -- --check + + manual: + name: Lua 5.2 manual data is current + needs: changes + if: needs.changes.outputs.manual == 'true' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # No `npm ci`: the generator uses only Node built-ins and `tar`. + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + - name: Cache the Lua source tarball + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: .cache/lua + key: lua-src-${{ hashFiles('third_party/lua52/tarball.mts') }} + - name: Regenerate and compare + run: npm run lua-manual -- --check diff --git a/.vscodeignore b/.vscodeignore index ea823e3..230ccc2 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -7,7 +7,7 @@ !package.json !package.nls.json !package.nls.*.json -!l10n/** +!l10n/bundle.l10n*.json !language-configuration/** !syntaxes/** !images/icon.png diff --git a/CHANGELOG.md b/CHANGELOG.md index f140d17..fe5c6a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,10 +69,30 @@ the extension live in [`docs/CHANGELOG.vsix.md`](docs/CHANGELOG.vsix.md). `**/*.[mM][eE][nN][uU]`, and creates and deletes of folders), workspace folder changes and document closes. `files.exclude` is honored as VS Code's explorer applies it, with an original matcher checked against VS Code's own; changing it rescans. +- Hover (`textDocument/hover`), in Markdown or plain text as the client prefers: + - Lua 5.2 library functions, values and module tables, with the text of the + [Lua 5.2 manual](https://www.lua.org/manual/5.2/manual.html) verbatim and a link to the entry: + the basic functions and the `string`, `table`, `math`, `bit32` and `debug` libraries, the ones + the engine opens (IESDP), also as `_G.string.format` and `("x"):rep()`. The text is generated + from `doc/manual.html` of the checksum-verified Lua 5.2.4 tarball (`npm run lua-manual`, checked + in CI) and is identical to the online manual's. `io`, `os`, `package` (`require`) and + `coroutine` are not documented, as the engine does not provide them. + - `print`: a note that the engine replaces it, linking IESDP's *Engine Lua globals*, instead of + the manual's description. + - EEex and game functions (`EEex_*`, `Infinity_*`, `C:AddGold`, also called as `C.AddGold`): + the name and a link to EEex-Docs; no EEex-Docs text is copied. + - Locals and globals of the document: how they are declared (`local function f(a, b)`, + `(parameter) a`, `(for variable) i`, `(global) function G(x)`), from the first assignment for + a global, shared across the Lua chunks of a `.menu` file. + - No library text for names a local shadows (`local string = {}`), globals or library members the + document assigns itself (`string = …`, `string.format = …`, `function string.trim()`), or names + resolved through a local `_ENV`. + - The server's own labels are localized into the 14 VS Code display languages from the client's + `locale` (`InitializeParams.locale`), in every editor. - Error-tolerant Lua 5.2 parser and scope analysis (`src/server/syntax/`), checked against the official compiler by a differential test; it publishes no diagnostics of its own. -- Localization of the manifest and UI strings into all 14 VS Code display languages - (machine-produced; review welcome). +- Localization of the manifest, UI strings and the language server's hover labels into all 14 VS + Code display languages (machine-produced; review welcome). - Setup guides for Sublime Text, Neovim, Emacs, JetBrains IDEs, Helix, Zed, Kate, Notepad++ and Geany. - EEex documentation index (`data/eeex/`): names and deep links only, synced from the published Read the Docs build. diff --git a/CLAUDE.md b/CLAUDE.md index 98992de..63973de 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,7 +11,7 @@ |---|---| | Name | `IE Lua Language Server` | | Publisher | `infinity-engine-tools` | -| Purpose | Lua 5.2 language support (diagnostics, document and workspace symbols, folding, and same-file definition, references and rename now; more LSP features planned) for Infinity Engine EE `.lua` files and the Lua embedded in `.menu` files, usable from VS Code and other LSP editors | +| Purpose | Lua 5.2 language support (diagnostics, hover, document and workspace symbols, folding, and same-file definition, references and rename now; more LSP features planned) for Infinity Engine EE `.lua` files and the Lua embedded in `.menu` files, usable from VS Code and other LSP editors | | Language | TypeScript (strict) | | Bundler | esbuild (two bundles: client + language server) | | Minimum VS Code | `^1.91.0` (see `engines.vscode` in `package.json`; required by `vscode-languageclient` ≥ 10) | @@ -32,6 +32,8 @@ │ ├── server/ # Language server (separate Node process) │ │ ├── server.ts # Connection, capabilities, handlers │ │ ├── features/ # completion.ts, diagnostics.ts, hover.ts, ... +│ │ ├── hover/ # Hover targets, library knowledge and rendering (pure, no LSP imports) +│ │ ├── l10n.ts # Server messages in the client's locale (tables in l10n/server/) │ │ ├── syntax/ # Lua 5.2 lexer, parser, scopes, symbols, folding (pure, no LSP imports) │ │ ├── validation/ # Pure analysis logic (no LSP imports) — unit-tested directly │ │ └── workspace/ # Workspace index, files.exclude glob matching (fs injected; no LSP) @@ -42,6 +44,7 @@ │ └── fixtures/workspace/ # Original fixtures only — never copy game files ├── third_party/lua52/ # Official Lua 5.2.4 → WASM (reproducible build; dist/ is generated) ├── data/eeex/ # Generated EEex docs index (names + links only; see scripts/eeex-docs/) +├── data/lua52/ # Lua 5.2 manual library text, generated by scripts/lua-manual/ (CI-checked) ├── scripts/ # Repo tooling in TypeScript (`.mts`, run by Node's type stripping) ├── docs/editors/ # Setup guides for non-VS Code editors ├── dist/ # esbuild output — generated, never edit @@ -71,6 +74,7 @@ The server runs in a separate process where the `vscode` module does not exist. | Localization check | `npm run check-l10n` | | Third-party notices | `npm run notices` (after `npm run package`; `-- --check` in CI) | | Rebuild Lua WASM | `npm run build:wasm` (needs pinned emsdk; see CONTRIBUTING.md) | +| Regenerate Lua manual data | `npm run lua-manual` (`-- --check` in CI) | | Build VSIX | `npx @vscode/vsce package --no-dependencies --changelog-path docs/CHANGELOG.vsix.md` | **Definition of done for any change:** `check-types`, `lint` and `test:unit` all pass. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4987248..dc18930 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,11 +29,14 @@ server (port 6009). | `src/client/` | VS Code extension host code: activation, command, settings, language client | | `src/server/` | Language server (separate Node process; no `vscode` import) | | `src/server/validation/` | Pure validation logic, unit-tested without LSP or VS Code | +| `src/server/hover/` | What a hover describes and its text (pure; library data from `data/lua52/` and `data/eeex/`) | | `src/server/syntax/` | Error-tolerant Lua 5.2 parser, scope analysis, document symbols and folding (pure; checked against the official compiler by `test/unit/server/syntax/differential.test.ts`) | | `src/server/workspace/` | Index of the workspace's Lua and `.menu` files, and `files.exclude` matching as VS Code applies it (file system injected, unit-tested with an in-memory one) | | `src/shared/` | Types and constants used by both sides | | `third_party/lua52/` | Reproducible build of the official Lua 5.2.4 compiler to WebAssembly | | `data/eeex/` | Generated EEex documentation index (names and links) | +| `data/lua52/` | Lua 5.2 library reference generated from the official manual (see below) | +| `l10n/server/` | The language server's own messages, per locale | | `scripts/` | Repository tooling (TypeScript run directly by Node.js) | | `test/unit/`, `test/integration/` | Mocha unit tests; VS Code integration tests | | `docs/editors/` | Setup guides for other editors | @@ -53,6 +56,7 @@ See [`CLAUDE.md`](CLAUDE.md) for the architecture rules. | `npm run package` | Production bundle | | `npm run notices` | Regenerate `THIRD_PARTY_NOTICES.md` (after `npm run package`) | | `npm run build:wasm` | Rebuild the Lua 5.2 WebAssembly module (needs Emscripten, see below) | +| `npm run lua-manual` | Regenerate `data/lua52/manual.json` from the official Lua 5.2 manual (see below) | **Definition of done:** `check-types`, `lint` and `test:unit` pass. Run `npm test` too when you touch activation, commands, settings or the language client/server wiring. @@ -91,6 +95,9 @@ The extension is translated into the 14 display languages VS Code offers - Manifest strings: `package.nls.json` (English) and `package.nls..json`. - Runtime strings: `vscode.l10n.t('…')` in `src/client/`. After adding or changing one, run `npx @vscode/l10n-dev export --outDir l10n src/client` and update every `l10n/bundle.l10n..json`. +- Language server strings: `messages.t('key', …)` in `src/server/` (`src/server/l10n.ts`), with the + English text in `l10n/server/messages.json` and one `l10n/server/messages..json` per + locale. The server picks the table from the client's `locale`, so they work in every editor. - Keep code spans, setting links (`` `#ieLua.validate.mode#` ``) and `{0}` placeholders unchanged, and refer to commands by the locale's translated title. `npm run check-l10n` enforces all of this. @@ -112,6 +119,22 @@ npm run build:wasm -- --check # verify the committed files are reproducible The Emscripten version is pinned in `third_party/lua52/build.mts` (`EMSCRIPTEN_VERSION`); CI reads it from there. The Lua tarball is verified against the SHA-256 published on . +## The Lua 5.2 manual data + +Hovers quote the library reference of the Lua 5.2 manual from `data/lua52/manual.json`, which is +generated and committed. `npm run lua-manual` rebuilds it from `doc/manual.html` in the same +checksum-verified Lua 5.2.4 tarball as the WebAssembly module (downloaded once into `.cache/lua`): + +```sh +npm run lua-manual # regenerate +npm run lua-manual -- --check # verify the committed file (CI does this) +npm run lua-manual -- --compare-online # audit: compare with https://www.lua.org/manual/5.2/ +``` + +Only the libraries the game engine opens are included (see CLAUDE.md, section 7). The converter +in `scripts/lua-manual/convert.mts` accepts exactly the HTML the manual uses and fails on anything +else; its header lists the three places where Markdown cannot show the manual's formatting. + ## Releases Releases are private: VSIX files are attached to [GitHub Releases](https://github.com/4Luke4/IE-Lua-Language-Server/releases). diff --git a/README.md b/README.md index c08e741..c55c911 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ Lua language support for the **Infinity Engine Enhanced Edition** games and the `.menu` files such as `UI.MENU`. > [!NOTE] -> This is an early version. It currently provides **syntax diagnostics**, **document symbols**, -> **workspace symbols**, **folding**, and **go to definition**, **find references** and **rename** -> within a file; completion, hover, cross-file navigation, formatting and more are planned. +> This is an early version. It currently provides **syntax diagnostics**, **hover**, +> **document symbols**, **workspace symbols**, **folding**, and **go to definition**, +> **find references** and **rename** within a file; completion, cross-file navigation, formatting +> and more are planned. ## Features @@ -36,6 +37,13 @@ Lua language support for the **Infinity Engine Enhanced Edition** games and the you haven't opened; files hidden with *Files: Exclude* are left out. - **Folding that follows the code:** functions, loops, each `if`/`elseif`/`else` branch, tables, comments, and every `{ … }` block and Lua script of a `.menu` file. +- **Documentation on hover.** Lua functions such as `string.format` show their description from + the [Lua 5.2 manual](https://www.lua.org/manual/5.2/manual.html), word for word, with a link to + it. Only the libraries the game provides are documented (`io`, `os`, `require` and coroutines + are not), and `print` tells you that the game replaces it. EEex and game functions such as + `Infinity_DisplayString` or `C:AddGold` link to the + [EEex documentation](https://eeex-docs.readthedocs.io/en/latest/), and your own variables show + how they are declared. - **Go to Definition, Find All References and Rename Symbol** for variables within a file. Locals follow Lua's scoping rules; globals are followed across all the Lua of a `.menu` file. Rename refuses, and says why, when it could change what the code does: a name already in use nearby, diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 5d83ffa..e076dd4 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -350,6 +350,37 @@ obstacle to adoption, that text has been removed. compiled object forms to be redistributed without the attribution conditions of sections 4(a), 4(b) and 4(d) of the Apache License 2.0. +## Lua 5.2 Reference Manual + +Hovers quote the library reference of the Lua 5.2 Reference Manual (lua-5.2.4/doc/manual.html in +), converted to Markdown by +[`scripts/lua-manual/`](scripts/lua-manual/). The manual reads: +"Copyright © 2011–2015 Lua.org, PUC-Rio. Freely available under the terms of the Lua license." The Lua license: + +```text +Source: lua-5.2.4.tar.gz, doc/readme.html, section "License" (https://www.lua.org/ftp/lua-5.2.4.tar.gz). + +Copyright © 1994–2015 Lua.org, PUC-Rio. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +``` + ## npm packages ### balanced-match 4.0.4 diff --git a/data/lua52/manual.json b/data/lua52/manual.json new file mode 100644 index 0000000..68fa756 --- /dev/null +++ b/data/lua52/manual.json @@ -0,0 +1,998 @@ +{ + "source": { + "url": "https://www.lua.org/ftp/lua-5.2.4.tar.gz", + "sha256": "b9e2e4aad6789b3b63a056d442f7b39f0ecfca3ae0f1fc0ae4e9614401b69f4b", + "member": "lua-5.2.4/doc/manual.html", + "encoding": "iso-8859-1" + }, + "title": "Lua 5.2 Reference Manual", + "copyright": "Copyright © 2011–2015 Lua.org, PUC-Rio. Freely available under the terms of the Lua license.", + "baseUrl": "https://www.lua.org/manual/5.2/manual.html", + "sections": [ + { + "number": "6.1", + "title": "Basic Functions" + }, + { + "number": "6.4", + "title": "String Manipulation", + "module": "string" + }, + { + "number": "6.5", + "title": "Table Manipulation", + "module": "table" + }, + { + "number": "6.6", + "title": "Mathematical Functions", + "module": "math" + }, + { + "number": "6.7", + "title": "Bitwise Operations", + "module": "bit32" + }, + { + "number": "6.10", + "title": "The Debug Library", + "module": "debug" + } + ], + "entries": [ + { + "name": "assert", + "kind": "function", + "section": "6.1", + "anchor": "pdf-assert", + "heading": "assert (v [, message])", + "markdown": "Issues an error when the value of its argument `v` is false (i.e., **nil** or **false**); otherwise, returns all its arguments. `message` is an error message; when absent, it defaults to \"assertion failed\\!\"", + "plaintext": "Issues an error when the value of its argument v is false (i.e., nil or false); otherwise, returns all its arguments. message is an error message; when absent, it defaults to \"assertion failed!\"" + }, + { + "name": "collectgarbage", + "kind": "function", + "section": "6.1", + "anchor": "pdf-collectgarbage", + "heading": "collectgarbage ([opt [, arg]])", + "markdown": "This function is a generic interface to the garbage collector. It performs different functions according to its first argument, `opt`:\n\n- **\"`collect`\":** performs a full garbage-collection cycle. This is the default option.\n\n- **\"`stop`\":** stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.\n\n- **\"`restart`\":** restarts automatic execution of the garbage collector.\n\n- **\"`count`\":** returns the total memory in use by Lua (in Kbytes) and a second value with the total memory in bytes modulo 1024. The first value has a fractional part, so the following equality is always true:\n\n ```\n k, b = collectgarbage(\"count\")\n assert(k*1024 == math.floor(k)*1024 + b)\n ```\n\n (The second result is useful when Lua is compiled with a non floating-point type for numbers.)\n\n- **\"`step`\":** performs a garbage-collection step. The step \"size\" is controlled by `arg` (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of `arg`. Returns **true** if the step finished a collection cycle.\n\n- **\"`setpause`\":** sets `arg` as the new value for the *pause* of the collector (see [§2.5](https://www.lua.org/manual/5.2/manual.html#2.5)). Returns the previous value for *pause*.\n\n- **\"`setstepmul`\":** sets `arg` as the new value for the *step multiplier* of the collector (see [§2.5](https://www.lua.org/manual/5.2/manual.html#2.5)). Returns the previous value for *step*.\n\n- **\"`isrunning`\":** returns a boolean that tells whether the collector is running (i.e., not stopped).\n\n- **\"`generational`\":** changes the collector to generational mode. This is an experimental feature (see [§2.5](https://www.lua.org/manual/5.2/manual.html#2.5)).\n\n- **\"`incremental`\":** changes the collector to incremental mode. This is the default mode.", + "plaintext": "This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:\n\n- \"collect\": performs a full garbage-collection cycle. This is the default option.\n\n- \"stop\": stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.\n\n- \"restart\": restarts automatic execution of the garbage collector.\n\n- \"count\": returns the total memory in use by Lua (in Kbytes) and a second value with the total memory in bytes modulo 1024. The first value has a fractional part, so the following equality is always true:\n\n k, b = collectgarbage(\"count\")\n assert(k*1024 == math.floor(k)*1024 + b)\n\n (The second result is useful when Lua is compiled with a non floating-point type for numbers.)\n\n- \"step\": performs a garbage-collection step. The step \"size\" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle.\n\n- \"setpause\": sets arg as the new value for the pause of the collector (see §2.5 (https://www.lua.org/manual/5.2/manual.html#2.5)). Returns the previous value for pause.\n\n- \"setstepmul\": sets arg as the new value for the step multiplier of the collector (see §2.5 (https://www.lua.org/manual/5.2/manual.html#2.5)). Returns the previous value for step.\n\n- \"isrunning\": returns a boolean that tells whether the collector is running (i.e., not stopped).\n\n- \"generational\": changes the collector to generational mode. This is an experimental feature (see §2.5 (https://www.lua.org/manual/5.2/manual.html#2.5)).\n\n- \"incremental\": changes the collector to incremental mode. This is the default mode." + }, + { + "name": "dofile", + "kind": "function", + "section": "6.1", + "anchor": "pdf-dofile", + "heading": "dofile ([filename])", + "markdown": "Opens the named file and executes its contents as a Lua chunk. When called without arguments, `dofile` executes the contents of the standard input (`stdin`). Returns all values returned by the chunk. In case of errors, `dofile` propagates the error to its caller (that is, `dofile` does not run in protected mode).", + "plaintext": "Opens the named file and executes its contents as a Lua chunk. When called without arguments, dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller (that is, dofile does not run in protected mode)." + }, + { + "name": "error", + "kind": "function", + "section": "6.1", + "anchor": "pdf-error", + "heading": "error (message [, level])", + "markdown": "Terminates the last protected function called and returns `message` as the error message. Function `error` never returns.\n\nUsually, `error` adds some information about the error position at the beginning of the message, if the message is a string. The `level` argument specifies how to get the error position. With level 1 (the default), the error position is where the `error` function was called. Level 2 points the error to where the function that called `error` was called; and so on. Passing a level 0 avoids the addition of error position information to the message.", + "plaintext": "Terminates the last protected function called and returns message as the error message. Function error never returns.\n\nUsually, error adds some information about the error position at the beginning of the message, if the message is a string. The level argument specifies how to get the error position. With level 1 (the default), the error position is where the error function was called. Level 2 points the error to where the function that called error was called; and so on. Passing a level 0 avoids the addition of error position information to the message." + }, + { + "name": "_G", + "kind": "value", + "section": "6.1", + "anchor": "pdf-_G", + "heading": "_G", + "markdown": "A global variable (not a function) that holds the global environment (see [§2.2](https://www.lua.org/manual/5.2/manual.html#2.2)). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa.", + "plaintext": "A global variable (not a function) that holds the global environment (see §2.2 (https://www.lua.org/manual/5.2/manual.html#2.2)). Lua itself does not use this variable; changing its value does not affect any environment, nor vice-versa." + }, + { + "name": "getmetatable", + "kind": "function", + "section": "6.1", + "anchor": "pdf-getmetatable", + "heading": "getmetatable (object)", + "markdown": "If `object` does not have a metatable, returns **nil**. Otherwise, if the object's metatable has a `\"__metatable\"` field, returns the associated value. Otherwise, returns the metatable of the given object.", + "plaintext": "If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a \"__metatable\" field, returns the associated value. Otherwise, returns the metatable of the given object." + }, + { + "name": "ipairs", + "kind": "function", + "section": "6.1", + "anchor": "pdf-ipairs", + "heading": "ipairs (t)", + "markdown": "If `t` has a metamethod `__ipairs`, calls it with `t` as argument and returns the first three results from the call.\n\nOtherwise, returns three values: an iterator function, the table `t`, and 0, so that the construction\n\n```\n for i,v in ipairs(t) do body end\n```\n\nwill iterate over the pairs (`1,t[1]`), (`2,t[2]`), ..., up to the first integer key absent from the table.", + "plaintext": "If t has a metamethod __ipairs, calls it with t as argument and returns the first three results from the call.\n\nOtherwise, returns three values: an iterator function, the table t, and 0, so that the construction\n\n for i,v in ipairs(t) do body end\n\nwill iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table." + }, + { + "name": "load", + "kind": "function", + "section": "6.1", + "anchor": "pdf-load", + "heading": "load (ld [, source [, mode [, env]]])", + "markdown": "Loads a chunk.\n\nIf `ld` is a string, the chunk is this string. If `ld` is a function, `load` calls it repeatedly to get the chunk pieces. Each call to `ld` must return a string that concatenates with previous results. A return of an empty string, **nil**, or no value signals the end of the chunk.\n\nIf there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns **nil** plus the error message.\n\nIf the resulting function has upvalues, the first upvalue is set to the value of `env`, if that parameter is given, or to the value of the global environment. (When you load a main chunk, the resulting function will always have exactly one upvalue, the `_ENV` variable (see [§2.2](https://www.lua.org/manual/5.2/manual.html#2.2)). When you load a binary chunk created from a function (see [`string.dump`](https://www.lua.org/manual/5.2/manual.html#pdf-string.dump)), the resulting function can have arbitrary upvalues.)\n\n`source` is used as the source of the chunk for error messages and debug information (see [§4.9](https://www.lua.org/manual/5.2/manual.html#4.9)). When absent, it defaults to `ld`, if `ld` is a string, or to \"`=(load)`\" otherwise.\n\nThe string `mode` controls whether the chunk can be text or binary (that is, a precompiled chunk). It may be the string \"`b`\" (only binary chunks), \"`t`\" (only text chunks), or \"`bt`\" (both binary and text). The default is \"`bt`\".", + "plaintext": "Loads a chunk.\n\nIf ld is a string, the chunk is this string. If ld is a function, load calls it repeatedly to get the chunk pieces. Each call to ld must return a string that concatenates with previous results. A return of an empty string, nil, or no value signals the end of the chunk.\n\nIf there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message.\n\nIf the resulting function has upvalues, the first upvalue is set to the value of env, if that parameter is given, or to the value of the global environment. (When you load a main chunk, the resulting function will always have exactly one upvalue, the _ENV variable (see §2.2 (https://www.lua.org/manual/5.2/manual.html#2.2)). When you load a binary chunk created from a function (see string.dump (https://www.lua.org/manual/5.2/manual.html#pdf-string.dump)), the resulting function can have arbitrary upvalues.)\n\nsource is used as the source of the chunk for error messages and debug information (see §4.9 (https://www.lua.org/manual/5.2/manual.html#4.9)). When absent, it defaults to ld, if ld is a string, or to \"=(load)\" otherwise.\n\nThe string mode controls whether the chunk can be text or binary (that is, a precompiled chunk). It may be the string \"b\" (only binary chunks), \"t\" (only text chunks), or \"bt\" (both binary and text). The default is \"bt\"." + }, + { + "name": "loadfile", + "kind": "function", + "section": "6.1", + "anchor": "pdf-loadfile", + "heading": "loadfile ([filename [, mode [, env]]])", + "markdown": "Similar to [`load`](https://www.lua.org/manual/5.2/manual.html#pdf-load), but gets the chunk from file `filename` or from the standard input, if no file name is given.", + "plaintext": "Similar to load (https://www.lua.org/manual/5.2/manual.html#pdf-load), but gets the chunk from file filename or from the standard input, if no file name is given." + }, + { + "name": "next", + "kind": "function", + "section": "6.1", + "anchor": "pdf-next", + "heading": "next (table [, index])", + "markdown": "Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. `next` returns the next index of the table and its associated value. When called with **nil** as its second argument, `next` returns an initial index and its associated value. When called with the last index, or with **nil** in an empty table, `next` returns **nil**. If the second argument is absent, then it is interpreted as **nil**. In particular, you can use `next(t)` to check whether a table is empty.\n\nThe order in which the indices are enumerated is not specified, *even for numeric indices*. (To traverse a table in numeric order, use a numerical **for**.)\n\nThe behavior of `next` is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.", + "plaintext": "Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. next returns the next index of the table and its associated value. When called with nil as its second argument, next returns an initial index and its associated value. When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent, then it is interpreted as nil. In particular, you can use next(t) to check whether a table is empty.\n\nThe order in which the indices are enumerated is not specified, even for numeric indices. (To traverse a table in numeric order, use a numerical for.)\n\nThe behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields." + }, + { + "name": "pairs", + "kind": "function", + "section": "6.1", + "anchor": "pdf-pairs", + "heading": "pairs (t)", + "markdown": "If `t` has a metamethod `__pairs`, calls it with `t` as argument and returns the first three results from the call.\n\nOtherwise, returns three values: the [`next`](https://www.lua.org/manual/5.2/manual.html#pdf-next) function, the table `t`, and **nil**, so that the construction\n\n```\n for k,v in pairs(t) do body end\n```\n\nwill iterate over all key–value pairs of table `t`.\n\nSee function [`next`](https://www.lua.org/manual/5.2/manual.html#pdf-next) for the caveats of modifying the table during its traversal.", + "plaintext": "If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.\n\nOtherwise, returns three values: the next (https://www.lua.org/manual/5.2/manual.html#pdf-next) function, the table t, and nil, so that the construction\n\n for k,v in pairs(t) do body end\n\nwill iterate over all key–value pairs of table t.\n\nSee function next (https://www.lua.org/manual/5.2/manual.html#pdf-next) for the caveats of modifying the table during its traversal." + }, + { + "name": "pcall", + "kind": "function", + "section": "6.1", + "anchor": "pdf-pcall", + "heading": "pcall (f [, arg1, ···])", + "markdown": "Calls function `f` with the given arguments in *protected mode*. This means that any error inside `f` is not propagated; instead, `pcall` catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, `pcall` also returns all results from the call, after this first result. In case of any error, `pcall` returns **false** plus the error message.", + "plaintext": "Calls function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message." + }, + { + "name": "print", + "kind": "function", + "section": "6.1", + "anchor": "pdf-print", + "heading": "print (···)", + "markdown": "Receives any number of arguments and prints their values to `stdout`, using the [`tostring`](https://www.lua.org/manual/5.2/manual.html#pdf-tostring) function to convert each argument to a string. `print` is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use [`string.format`](https://www.lua.org/manual/5.2/manual.html#pdf-string.format) and [`io.write`](https://www.lua.org/manual/5.2/manual.html#pdf-io.write).", + "plaintext": "Receives any number of arguments and prints their values to stdout, using the tostring (https://www.lua.org/manual/5.2/manual.html#pdf-tostring) function to convert each argument to a string. print is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use string.format (https://www.lua.org/manual/5.2/manual.html#pdf-string.format) and io.write (https://www.lua.org/manual/5.2/manual.html#pdf-io.write)." + }, + { + "name": "rawequal", + "kind": "function", + "section": "6.1", + "anchor": "pdf-rawequal", + "heading": "rawequal (v1, v2)", + "markdown": "Checks whether `v1` is equal to `v2`, without invoking any metamethod. Returns a boolean.", + "plaintext": "Checks whether v1 is equal to v2, without invoking any metamethod. Returns a boolean." + }, + { + "name": "rawget", + "kind": "function", + "section": "6.1", + "anchor": "pdf-rawget", + "heading": "rawget (table, index)", + "markdown": "Gets the real value of `table[index]`, without invoking any metamethod. `table` must be a table; `index` may be any value.", + "plaintext": "Gets the real value of table[index], without invoking any metamethod. table must be a table; index may be any value." + }, + { + "name": "rawlen", + "kind": "function", + "section": "6.1", + "anchor": "pdf-rawlen", + "heading": "rawlen (v)", + "markdown": "Returns the length of the object `v`, which must be a table or a string, without invoking any metamethod. Returns an integer number.", + "plaintext": "Returns the length of the object v, which must be a table or a string, without invoking any metamethod. Returns an integer number." + }, + { + "name": "rawset", + "kind": "function", + "section": "6.1", + "anchor": "pdf-rawset", + "heading": "rawset (table, index, value)", + "markdown": "Sets the real value of `table[index]` to `value`, without invoking any metamethod. `table` must be a table, `index` any value different from **nil** and NaN, and `value` any Lua value.\n\nThis function returns `table`.", + "plaintext": "Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil and NaN, and value any Lua value.\n\nThis function returns table." + }, + { + "name": "select", + "kind": "function", + "section": "6.1", + "anchor": "pdf-select", + "heading": "select (index, ···)", + "markdown": "If `index` is a number, returns all arguments after argument number `index`; a negative number indexes from the end (-1 is the last argument). Otherwise, `index` must be the string `\"#\"`, and `select` returns the total number of extra arguments it received.", + "plaintext": "If index is a number, returns all arguments after argument number index; a negative number indexes from the end (-1 is the last argument). Otherwise, index must be the string \"#\", and select returns the total number of extra arguments it received." + }, + { + "name": "setmetatable", + "kind": "function", + "section": "6.1", + "anchor": "pdf-setmetatable", + "heading": "setmetatable (table, metatable)", + "markdown": "Sets the metatable for the given table. (You cannot change the metatable of other types from Lua, only from C.) If `metatable` is **nil**, removes the metatable of the given table. If the original metatable has a `\"__metatable\"` field, raises an error.\n\nThis function returns `table`.", + "plaintext": "Sets the metatable for the given table. (You cannot change the metatable of other types from Lua, only from C.) If metatable is nil, removes the metatable of the given table. If the original metatable has a \"__metatable\" field, raises an error.\n\nThis function returns table." + }, + { + "name": "tonumber", + "kind": "function", + "section": "6.1", + "anchor": "pdf-tonumber", + "heading": "tonumber (e [, base])", + "markdown": "When called with no `base`, `tonumber` tries to convert its argument to a number. If the argument is already a number or a string convertible to a number (see [§3.4.2](https://www.lua.org/manual/5.2/manual.html#3.4.2)), then `tonumber` returns this number; otherwise, it returns **nil**.\n\nWhen called with `base`, then `e` should be a string to be interpreted as an integer numeral in that base. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter '`A`' (in either upper or lower case) represents 10, '`B`' represents 11, and so forth, with '`Z`' representing 35. If the string `e` is not a valid numeral in the given base, the function returns **nil**.", + "plaintext": "When called with no base, tonumber tries to convert its argument to a number. If the argument is already a number or a string convertible to a number (see §3.4.2 (https://www.lua.org/manual/5.2/manual.html#3.4.2)), then tonumber returns this number; otherwise, it returns nil.\n\nWhen called with base, then e should be a string to be interpreted as an integer numeral in that base. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If the string e is not a valid numeral in the given base, the function returns nil." + }, + { + "name": "tostring", + "kind": "function", + "section": "6.1", + "anchor": "pdf-tostring", + "heading": "tostring (v)", + "markdown": "Receives a value of any type and converts it to a string in a reasonable format. (For complete control of how numbers are converted, use [`string.format`](https://www.lua.org/manual/5.2/manual.html#pdf-string.format).)\n\nIf the metatable of `v` has a `\"__tostring\"` field, then `tostring` calls the corresponding value with `v` as argument, and uses the result of the call as its result.", + "plaintext": "Receives a value of any type and converts it to a string in a reasonable format. (For complete control of how numbers are converted, use string.format (https://www.lua.org/manual/5.2/manual.html#pdf-string.format).)\n\nIf the metatable of v has a \"__tostring\" field, then tostring calls the corresponding value with v as argument, and uses the result of the call as its result." + }, + { + "name": "type", + "kind": "function", + "section": "6.1", + "anchor": "pdf-type", + "heading": "type (v)", + "markdown": "Returns the type of its only argument, coded as a string. The possible results of this function are \"`nil`\" (a string, not the value **nil**), \"`number`\", \"`string`\", \"`boolean`\", \"`table`\", \"`function`\", \"`thread`\", and \"`userdata`\".", + "plaintext": "Returns the type of its only argument, coded as a string. The possible results of this function are \"nil\" (a string, not the value nil), \"number\", \"string\", \"boolean\", \"table\", \"function\", \"thread\", and \"userdata\"." + }, + { + "name": "_VERSION", + "kind": "value", + "section": "6.1", + "anchor": "pdf-_VERSION", + "heading": "_VERSION", + "markdown": "A global variable (not a function) that holds a string containing the current interpreter version. The current contents of this variable is \"`Lua 5.2`\".", + "plaintext": "A global variable (not a function) that holds a string containing the current interpreter version. The current contents of this variable is \"Lua 5.2\"." + }, + { + "name": "xpcall", + "kind": "function", + "section": "6.1", + "anchor": "pdf-xpcall", + "heading": "xpcall (f, msgh [, arg1, ···])", + "markdown": "This function is similar to [`pcall`](https://www.lua.org/manual/5.2/manual.html#pdf-pcall), except that it sets a new message handler `msgh`.", + "plaintext": "This function is similar to pcall (https://www.lua.org/manual/5.2/manual.html#pdf-pcall), except that it sets a new message handler msgh." + }, + { + "name": "string", + "kind": "module", + "section": "6.4", + "anchor": "6.4", + "heading": "string", + "markdown": "This library provides generic functions for string manipulation, such as finding and extracting substrings, and pattern matching. When indexing a string in Lua, the first character is at position 1 (not at 0, as in C). Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on.\n\nThe string library provides all its functions inside the table `string`. It also sets a metatable for strings where the `__index` field points to the `string` table. Therefore, you can use the string functions in object-oriented style. For instance, `string.byte(s,i)` can be written as `s:byte(i)`.\n\nThe string library assumes one-byte character encodings.", + "plaintext": "This library provides generic functions for string manipulation, such as finding and extracting substrings, and pattern matching. When indexing a string in Lua, the first character is at position 1 (not at 0, as in C). Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on.\n\nThe string library provides all its functions inside the table string. It also sets a metatable for strings where the __index field points to the string table. Therefore, you can use the string functions in object-oriented style. For instance, string.byte(s,i) can be written as s:byte(i).\n\nThe string library assumes one-byte character encodings." + }, + { + "name": "string.byte", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.byte", + "heading": "string.byte (s [, i [, j]])", + "markdown": "Returns the internal numerical codes of the characters `s[i]`, `s[i+1]`, ..., `s[j]`. The default value for `i` is 1; the default value for `j` is `i`. These indices are corrected following the same rules of function [`string.sub`](https://www.lua.org/manual/5.2/manual.html#pdf-string.sub).\n\nNumerical codes are not necessarily portable across platforms.", + "plaintext": "Returns the internal numerical codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i. These indices are corrected following the same rules of function string.sub (https://www.lua.org/manual/5.2/manual.html#pdf-string.sub).\n\nNumerical codes are not necessarily portable across platforms." + }, + { + "name": "string.char", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.char", + "heading": "string.char (···)", + "markdown": "Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.\n\nNumerical codes are not necessarily portable across platforms.", + "plaintext": "Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.\n\nNumerical codes are not necessarily portable across platforms." + }, + { + "name": "string.dump", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.dump", + "heading": "string.dump (function)", + "markdown": "Returns a string containing a binary representation of the given function, so that a later [`load`](https://www.lua.org/manual/5.2/manual.html#pdf-load) on this string returns a copy of the function (but with new upvalues).", + "plaintext": "Returns a string containing a binary representation of the given function, so that a later load (https://www.lua.org/manual/5.2/manual.html#pdf-load) on this string returns a copy of the function (but with new upvalues)." + }, + { + "name": "string.find", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.find", + "heading": "string.find (s, pattern [, init [, plain]])", + "markdown": "Looks for the first match of `pattern` in the string `s`. If it finds a match, then `find` returns the indices of `s` where this occurrence starts and ends; otherwise, it returns **nil**. A third, optional numerical argument `init` specifies where to start the search; its default value is 1 and can be negative. A value of **true** as a fourth, optional argument `plain` turns off the pattern matching facilities, so the function does a plain \"find substring\" operation, with no characters in `pattern` being considered magic. Note that if `plain` is given, then `init` must be given as well.\n\nIf the pattern has captures, then in a successful match the captured values are also returned, after the two indices.", + "plaintext": "Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain \"find substring\" operation, with no characters in pattern being considered magic. Note that if plain is given, then init must be given as well.\n\nIf the pattern has captures, then in a successful match the captured values are also returned, after the two indices." + }, + { + "name": "string.format", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.format", + "heading": "string.format (formatstring, ···)", + "markdown": "Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the ISO C function `sprintf`. The only differences are that the options/modifiers `*`, `h`, `L`, `l`, `n`, and `p` are not supported and that there is an extra option, `q`. The `q` option formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter. For instance, the call\n\n```\n string.format('%q', 'a string with \"quotes\" and \\n new line')\n```\n\nmay produce the string:\n\n```\n \"a string with \\\"quotes\\\" and \\\n new line\"\n```\n\nOptions `A` and `a` (when available), `E`, `e`, `f`, `G`, and `g` all expect a number as argument. Options `c`, `d`, `i`, `o`, `u`, `X`, and `x` also expect a number, but the range of that number may be limited by the underlying C implementation. For options `o`, `u`, `X`, and `x`, the number cannot be negative. Option `q` expects a string; option `s` expects a string without embedded zeros. If the argument to option `s` is not a string, it is converted to one following the same rules of [`tostring`](https://www.lua.org/manual/5.2/manual.html#pdf-tostring).", + "plaintext": "Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the ISO C function sprintf. The only differences are that the options/modifiers *, h, L, l, n, and p are not supported and that there is an extra option, q. The q option formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter. For instance, the call\n\n string.format('%q', 'a string with \"quotes\" and \\n new line')\n\nmay produce the string:\n\n \"a string with \\\"quotes\\\" and \\\n new line\"\n\nOptions A and a (when available), E, e, f, G, and g all expect a number as argument. Options c, d, i, o, u, X, and x also expect a number, but the range of that number may be limited by the underlying C implementation. For options o, u, X, and x, the number cannot be negative. Option q expects a string; option s expects a string without embedded zeros. If the argument to option s is not a string, it is converted to one following the same rules of tostring (https://www.lua.org/manual/5.2/manual.html#pdf-tostring)." + }, + { + "name": "string.gmatch", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.gmatch", + "heading": "string.gmatch (s, pattern)", + "markdown": "Returns an iterator function that, each time it is called, returns the next captures from `pattern` over the string `s`. If `pattern` specifies no captures, then the whole match is produced in each call.\n\nAs an example, the following loop will iterate over all the words from string `s`, printing one per line:\n\n```\n s = \"hello world from Lua\"\n for w in string.gmatch(s, \"%a+\") do\n print(w)\n end\n```\n\nThe next example collects all pairs `key=value` from the given string into a table:\n\n```\n t = {}\n s = \"from=world, to=Lua\"\n for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n t[k] = v\n end\n```\n\nFor this function, a caret '`^`' at the start of a pattern does not work as an anchor, as this would prevent the iteration.", + "plaintext": "Returns an iterator function that, each time it is called, returns the next captures from pattern over the string s. If pattern specifies no captures, then the whole match is produced in each call.\n\nAs an example, the following loop will iterate over all the words from string s, printing one per line:\n\n s = \"hello world from Lua\"\n for w in string.gmatch(s, \"%a+\") do\n print(w)\n end\n\nThe next example collects all pairs key=value from the given string into a table:\n\n t = {}\n s = \"from=world, to=Lua\"\n for k, v in string.gmatch(s, \"(%w+)=(%w+)\") do\n t[k] = v\n end\n\nFor this function, a caret '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration." + }, + { + "name": "string.gsub", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.gsub", + "heading": "string.gsub (s, pattern, repl [, n])", + "markdown": "Returns a copy of `s` in which all (or the first `n`, if given) occurrences of the `pattern` have been replaced by a replacement string specified by `repl`, which can be a string, a table, or a function. `gsub` also returns, as its second value, the total number of matches that occurred. The name `gsub` comes from *Global SUBstitution*.\n\nIf `repl` is a string, then its value is used for replacement. The character `%` works as an escape character: any sequence in `repl` of the form `%`*`d`*, with *d* between 1 and 9, stands for the value of the *d*-th captured substring. The sequence `%0` stands for the whole match. The sequence `%%` stands for a single `%`.\n\nIf `repl` is a table, then the table is queried for every match, using the first capture as the key.\n\nIf `repl` is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order.\n\nIn any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture.\n\nIf the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is **false** or **nil**, then there is no replacement (that is, the original match is kept in the string).\n\nHere are some examples:\n\n```\n x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n --> x=\"hello hello world world\"\n \n x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n --> x=\"hello hello world\"\n \n x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n --> x=\"world hello Lua from\"\n \n x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n --> x=\"home = /home/roberto, user = roberto\"\n \n x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n return load(s)()\n end)\n --> x=\"4+5 = 9\"\n \n local t = {name=\"lua\", version=\"5.2\"}\n x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n --> x=\"lua-5.2.tar.gz\"\n```", + "plaintext": "Returns a copy of s in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred. The name gsub comes from Global SUBstitution.\n\nIf repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %d, with d between 1 and 9, stands for the value of the d-th captured substring. The sequence %0 stands for the whole match. The sequence %% stands for a single %.\n\nIf repl is a table, then the table is queried for every match, using the first capture as the key.\n\nIf repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order.\n\nIn any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture.\n\nIf the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string).\n\nHere are some examples:\n\n x = string.gsub(\"hello world\", \"(%w+)\", \"%1 %1\")\n --> x=\"hello hello world world\"\n \n x = string.gsub(\"hello world\", \"%w+\", \"%0 %0\", 1)\n --> x=\"hello hello world\"\n \n x = string.gsub(\"hello world from Lua\", \"(%w+)%s*(%w+)\", \"%2 %1\")\n --> x=\"world hello Lua from\"\n \n x = string.gsub(\"home = $HOME, user = $USER\", \"%$(%w+)\", os.getenv)\n --> x=\"home = /home/roberto, user = roberto\"\n \n x = string.gsub(\"4+5 = $return 4+5$\", \"%$(.-)%$\", function (s)\n return load(s)()\n end)\n --> x=\"4+5 = 9\"\n \n local t = {name=\"lua\", version=\"5.2\"}\n x = string.gsub(\"$name-$version.tar.gz\", \"%$(%w+)\", t)\n --> x=\"lua-5.2.tar.gz\"" + }, + { + "name": "string.len", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.len", + "heading": "string.len (s)", + "markdown": "Receives a string and returns its length. The empty string `\"\"` has length 0. Embedded zeros are counted, so `\"a\\000bc\\000\"` has length 5.", + "plaintext": "Receives a string and returns its length. The empty string \"\" has length 0. Embedded zeros are counted, so \"a\\000bc\\000\" has length 5." + }, + { + "name": "string.lower", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.lower", + "heading": "string.lower (s)", + "markdown": "Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.", + "plaintext": "Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale." + }, + { + "name": "string.match", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.match", + "heading": "string.match (s, pattern [, init])", + "markdown": "Looks for the first *match* of `pattern` in the string `s`. If it finds one, then `match` returns the captures from the pattern; otherwise it returns **nil**. If `pattern` specifies no captures, then the whole match is returned. A third, optional numerical argument `init` specifies where to start the search; its default value is 1 and can be negative.", + "plaintext": "Looks for the first match of pattern in the string s. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative." + }, + { + "name": "string.rep", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.rep", + "heading": "string.rep (s, n [, sep])", + "markdown": "Returns a string that is the concatenation of `n` copies of the string `s` separated by the string `sep`. The default value for `sep` is the empty string (that is, no separator).", + "plaintext": "Returns a string that is the concatenation of n copies of the string s separated by the string sep. The default value for sep is the empty string (that is, no separator)." + }, + { + "name": "string.reverse", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.reverse", + "heading": "string.reverse (s)", + "markdown": "Returns a string that is the string `s` reversed.", + "plaintext": "Returns a string that is the string s reversed." + }, + { + "name": "string.sub", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.sub", + "heading": "string.sub (s, i [, j])", + "markdown": "Returns the substring of `s` that starts at `i` and continues until `j`; `i` and `j` can be negative. If `j` is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call `string.sub(s,1,j)` returns a prefix of `s` with length `j`, and `string.sub(s, -i)` returns a suffix of `s` with length `i`.\n\nIf, after the translation of negative indices, `i` is less than 1, it is corrected to 1. If `j` is greater than the string length, it is corrected to that length. If, after these corrections, `i` is greater than `j`, the function returns the empty string.", + "plaintext": "Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.\n\nIf, after the translation of negative indices, i is less than 1, it is corrected to 1. If j is greater than the string length, it is corrected to that length. If, after these corrections, i is greater than j, the function returns the empty string." + }, + { + "name": "string.upper", + "kind": "function", + "section": "6.4", + "anchor": "pdf-string.upper", + "heading": "string.upper (s)", + "markdown": "Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.", + "plaintext": "Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale." + }, + { + "name": "table", + "kind": "module", + "section": "6.5", + "anchor": "6.5", + "heading": "table", + "markdown": "This library provides generic functions for table manipulation. It provides all its functions inside the table `table`.\n\nRemember that, whenever an operation needs the length of a table, the table should be a proper sequence or have a `__len` metamethod (see [§3.4.6](https://www.lua.org/manual/5.2/manual.html#3.4.6)). All functions ignore non-numeric keys in tables given as arguments.\n\nFor performance reasons, all table accesses (get/set) performed by these functions are raw.", + "plaintext": "This library provides generic functions for table manipulation. It provides all its functions inside the table table.\n\nRemember that, whenever an operation needs the length of a table, the table should be a proper sequence or have a __len metamethod (see §3.4.6 (https://www.lua.org/manual/5.2/manual.html#3.4.6)). All functions ignore non-numeric keys in tables given as arguments.\n\nFor performance reasons, all table accesses (get/set) performed by these functions are raw." + }, + { + "name": "table.concat", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.concat", + "heading": "table.concat (list [, sep [, i [, j]]])", + "markdown": "Given a list where all elements are strings or numbers, returns the string `list[i]..sep..list[i+1] ··· sep..list[j]`. The default value for `sep` is the empty string, the default for `i` is 1, and the default for `j` is `#list`. If `i` is greater than `j`, returns the empty string.", + "plaintext": "Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ··· sep..list[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is #list. If i is greater than j, returns the empty string." + }, + { + "name": "table.insert", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.insert", + "heading": "table.insert (list, [pos,] value)", + "markdown": "Inserts element `value` at position `pos` in `list`, shifting up the elements `list[pos], list[pos+1], ···, list[#list]`. The default value for `pos` is `#list+1`, so that a call `table.insert(t,x)` inserts `x` at the end of list `t`.", + "plaintext": "Inserts element value at position pos in list, shifting up the elements list[pos], list[pos+1], ···, list[#list]. The default value for pos is #list+1, so that a call table.insert(t,x) inserts x at the end of list t." + }, + { + "name": "table.pack", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.pack", + "heading": "table.pack (···)", + "markdown": "Returns a new table with all parameters stored into keys 1, 2, etc. and with a field \"`n`\" with the total number of parameters. Note that the resulting table may not be a sequence.", + "plaintext": "Returns a new table with all parameters stored into keys 1, 2, etc. and with a field \"n\" with the total number of parameters. Note that the resulting table may not be a sequence." + }, + { + "name": "table.remove", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.remove", + "heading": "table.remove (list [, pos])", + "markdown": "Removes from `list` the element at position `pos`, returning the value of the removed element. When `pos` is an integer between 1 and `#list`, it shifts down the elements `list[pos+1], list[pos+2], ···, list[#list]` and erases element `list[#list]`; The index `pos` can also be 0 when `#list` is 0, or `#list + 1`; in those cases, the function erases the element `list[pos]`.\n\nThe default value for `pos` is `#list`, so that a call `table.remove(t)` removes the last element of list `t`.", + "plaintext": "Removes from list the element at position pos, returning the value of the removed element. When pos is an integer between 1 and #list, it shifts down the elements list[pos+1], list[pos+2], ···, list[#list] and erases element list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; in those cases, the function erases the element list[pos].\n\nThe default value for pos is #list, so that a call table.remove(t) removes the last element of list t." + }, + { + "name": "table.sort", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.sort", + "heading": "table.sort (list [, comp])", + "markdown": "Sorts list elements in a given order, *in-place*, from `list[1]` to `list[#list]`. If `comp` is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that `not comp(list[i+1],list[i])` will be true after the sort). If `comp` is not given, then the standard Lua operator `<` is used instead.\n\nThe sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.", + "plaintext": "Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that not comp(list[i+1],list[i]) will be true after the sort). If comp is not given, then the standard Lua operator < is used instead.\n\nThe sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort." + }, + { + "name": "table.unpack", + "kind": "function", + "section": "6.5", + "anchor": "pdf-table.unpack", + "heading": "table.unpack (list [, i [, j]])", + "markdown": "Returns the elements from the given table. This function is equivalent to\n\n```\n return list[i], list[i+1], ···, list[j]\n```\n\nBy default, `i` is 1 and `j` is `#list`.", + "plaintext": "Returns the elements from the given table. This function is equivalent to\n\n return list[i], list[i+1], ···, list[j]\n\nBy default, i is 1 and j is #list." + }, + { + "name": "math", + "kind": "module", + "section": "6.6", + "anchor": "6.6", + "heading": "math", + "markdown": "This library is an interface to the standard C math library. It provides all its functions inside the table `math`.", + "plaintext": "This library is an interface to the standard C math library. It provides all its functions inside the table math." + }, + { + "name": "math.abs", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.abs", + "heading": "math.abs (x)", + "markdown": "Returns the absolute value of `x`.", + "plaintext": "Returns the absolute value of x." + }, + { + "name": "math.acos", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.acos", + "heading": "math.acos (x)", + "markdown": "Returns the arc cosine of `x` (in radians).", + "plaintext": "Returns the arc cosine of x (in radians)." + }, + { + "name": "math.asin", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.asin", + "heading": "math.asin (x)", + "markdown": "Returns the arc sine of `x` (in radians).", + "plaintext": "Returns the arc sine of x (in radians)." + }, + { + "name": "math.atan", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.atan", + "heading": "math.atan (x)", + "markdown": "Returns the arc tangent of `x` (in radians).", + "plaintext": "Returns the arc tangent of x (in radians)." + }, + { + "name": "math.atan2", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.atan2", + "heading": "math.atan2 (y, x)", + "markdown": "Returns the arc tangent of `y/x` (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of `x` being zero.)", + "plaintext": "Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.)" + }, + { + "name": "math.ceil", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.ceil", + "heading": "math.ceil (x)", + "markdown": "Returns the smallest integer larger than or equal to `x`.", + "plaintext": "Returns the smallest integer larger than or equal to x." + }, + { + "name": "math.cos", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.cos", + "heading": "math.cos (x)", + "markdown": "Returns the cosine of `x` (assumed to be in radians).", + "plaintext": "Returns the cosine of x (assumed to be in radians)." + }, + { + "name": "math.cosh", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.cosh", + "heading": "math.cosh (x)", + "markdown": "Returns the hyperbolic cosine of `x`.", + "plaintext": "Returns the hyperbolic cosine of x." + }, + { + "name": "math.deg", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.deg", + "heading": "math.deg (x)", + "markdown": "Returns the angle `x` (given in radians) in degrees.", + "plaintext": "Returns the angle x (given in radians) in degrees." + }, + { + "name": "math.exp", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.exp", + "heading": "math.exp (x)", + "markdown": "Returns the value *eˣ*.", + "plaintext": "Returns the value eˣ." + }, + { + "name": "math.floor", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.floor", + "heading": "math.floor (x)", + "markdown": "Returns the largest integer smaller than or equal to `x`.", + "plaintext": "Returns the largest integer smaller than or equal to x." + }, + { + "name": "math.fmod", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.fmod", + "heading": "math.fmod (x, y)", + "markdown": "Returns the remainder of the division of `x` by `y` that rounds the quotient towards zero.", + "plaintext": "Returns the remainder of the division of x by y that rounds the quotient towards zero." + }, + { + "name": "math.frexp", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.frexp", + "heading": "math.frexp (x)", + "markdown": "Returns `m` and `e` such that *x = m2ᵉ*, `e` is an integer and the absolute value of `m` is in the range *\\[0.5, 1)* (or zero when `x` is zero).", + "plaintext": "Returns m and e such that x = m2ᵉ, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero)." + }, + { + "name": "math.huge", + "kind": "value", + "section": "6.6", + "anchor": "pdf-math.huge", + "heading": "math.huge", + "markdown": "The value `HUGE_VAL`, a value larger than or equal to any other numerical value.", + "plaintext": "The value HUGE_VAL, a value larger than or equal to any other numerical value." + }, + { + "name": "math.ldexp", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.ldexp", + "heading": "math.ldexp (m, e)", + "markdown": "Returns *m2ᵉ* (`e` should be an integer).", + "plaintext": "Returns m2ᵉ (e should be an integer)." + }, + { + "name": "math.log", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.log", + "heading": "math.log (x [, base])", + "markdown": "Returns the logarithm of `x` in the given base. The default for `base` is *e* (so that the function returns the natural logarithm of `x`).", + "plaintext": "Returns the logarithm of x in the given base. The default for base is e (so that the function returns the natural logarithm of x)." + }, + { + "name": "math.max", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.max", + "heading": "math.max (x, ···)", + "markdown": "Returns the maximum value among its arguments.", + "plaintext": "Returns the maximum value among its arguments." + }, + { + "name": "math.min", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.min", + "heading": "math.min (x, ···)", + "markdown": "Returns the minimum value among its arguments.", + "plaintext": "Returns the minimum value among its arguments." + }, + { + "name": "math.modf", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.modf", + "heading": "math.modf (x)", + "markdown": "Returns two numbers, the integral part of `x` and the fractional part of `x`.", + "plaintext": "Returns two numbers, the integral part of x and the fractional part of x." + }, + { + "name": "math.pi", + "kind": "value", + "section": "6.6", + "anchor": "pdf-math.pi", + "heading": "math.pi", + "markdown": "The value of *π*.", + "plaintext": "The value of π." + }, + { + "name": "math.pow", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.pow", + "heading": "math.pow (x, y)", + "markdown": "Returns *xʸ*. (You can also use the expression `x^y` to compute this value.)", + "plaintext": "Returns xʸ. (You can also use the expression x^y to compute this value.)" + }, + { + "name": "math.rad", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.rad", + "heading": "math.rad (x)", + "markdown": "Returns the angle `x` (given in degrees) in radians.", + "plaintext": "Returns the angle x (given in degrees) in radians." + }, + { + "name": "math.random", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.random", + "heading": "math.random ([m [, n]])", + "markdown": "This function is an interface to the simple pseudo-random generator function `rand` provided by Standard C. (No guarantees can be given for its statistical properties.)\n\nWhen called without arguments, returns a uniform pseudo-random real number in the range *\\[0,1)*. When called with an integer number `m`, `math.random` returns a uniform pseudo-random integer in the range *\\[1, m\\]*. When called with two integer numbers `m` and `n`, `math.random` returns a uniform pseudo-random integer in the range *\\[m, n\\]*.", + "plaintext": "This function is an interface to the simple pseudo-random generator function rand provided by Standard C. (No guarantees can be given for its statistical properties.)\n\nWhen called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n]." + }, + { + "name": "math.randomseed", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.randomseed", + "heading": "math.randomseed (x)", + "markdown": "Sets `x` as the \"seed\" for the pseudo-random generator: equal seeds produce equal sequences of numbers.", + "plaintext": "Sets x as the \"seed\" for the pseudo-random generator: equal seeds produce equal sequences of numbers." + }, + { + "name": "math.sin", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.sin", + "heading": "math.sin (x)", + "markdown": "Returns the sine of `x` (assumed to be in radians).", + "plaintext": "Returns the sine of x (assumed to be in radians)." + }, + { + "name": "math.sinh", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.sinh", + "heading": "math.sinh (x)", + "markdown": "Returns the hyperbolic sine of `x`.", + "plaintext": "Returns the hyperbolic sine of x." + }, + { + "name": "math.sqrt", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.sqrt", + "heading": "math.sqrt (x)", + "markdown": "Returns the square root of `x`. (You can also use the expression `x^0.5` to compute this value.)", + "plaintext": "Returns the square root of x. (You can also use the expression x^0.5 to compute this value.)" + }, + { + "name": "math.tan", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.tan", + "heading": "math.tan (x)", + "markdown": "Returns the tangent of `x` (assumed to be in radians).", + "plaintext": "Returns the tangent of x (assumed to be in radians)." + }, + { + "name": "math.tanh", + "kind": "function", + "section": "6.6", + "anchor": "pdf-math.tanh", + "heading": "math.tanh (x)", + "markdown": "Returns the hyperbolic tangent of `x`.", + "plaintext": "Returns the hyperbolic tangent of x." + }, + { + "name": "bit32", + "kind": "module", + "section": "6.7", + "anchor": "6.7", + "heading": "bit32", + "markdown": "This library provides bitwise operations. It provides all its functions inside the table `bit32`.\n\nUnless otherwise stated, all functions accept numeric arguments in the range *(-2⁵¹,+2⁵¹)*; each argument is normalized to the remainder of its division by *2³²* and truncated to an integer (in some unspecified way), so that its final value falls in the range *\\[0,2³² - 1\\]*. Similarly, all results are in the range *\\[0,2³² - 1\\]*. Note that `bit32.bnot(0)` is `0xFFFFFFFF`, which is different from `-1`.", + "plaintext": "This library provides bitwise operations. It provides all its functions inside the table bit32.\n\nUnless otherwise stated, all functions accept numeric arguments in the range (-2⁵¹,+2⁵¹); each argument is normalized to the remainder of its division by 2³² and truncated to an integer (in some unspecified way), so that its final value falls in the range [0,2³² - 1]. Similarly, all results are in the range [0,2³² - 1]. Note that bit32.bnot(0) is 0xFFFFFFFF, which is different from -1." + }, + { + "name": "bit32.arshift", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.arshift", + "heading": "bit32.arshift (x, disp)", + "markdown": "Returns the number `x` shifted `disp` bits to the right. The number `disp` may be any representable integer. Negative displacements shift to the left.\n\nThis shift operation is what is called arithmetic shift. Vacant bits on the left are filled with copies of the higher bit of `x`; vacant bits on the right are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero or `0xFFFFFFFF` (all original bits are shifted out).", + "plaintext": "Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left.\n\nThis shift operation is what is called arithmetic shift. Vacant bits on the left are filled with copies of the higher bit of x; vacant bits on the right are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero or 0xFFFFFFFF (all original bits are shifted out)." + }, + { + "name": "bit32.band", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.band", + "heading": "bit32.band (···)", + "markdown": "Returns the bitwise *and* of its operands.", + "plaintext": "Returns the bitwise and of its operands." + }, + { + "name": "bit32.bnot", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.bnot", + "heading": "bit32.bnot (x)", + "markdown": "Returns the bitwise negation of `x`. For any integer `x`, the following identity holds:\n\n```\n assert(bit32.bnot(x) == (-1 - x) % 2^32)\n```", + "plaintext": "Returns the bitwise negation of x. For any integer x, the following identity holds:\n\n assert(bit32.bnot(x) == (-1 - x) % 2^32)" + }, + { + "name": "bit32.bor", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.bor", + "heading": "bit32.bor (···)", + "markdown": "Returns the bitwise *or* of its operands.", + "plaintext": "Returns the bitwise or of its operands." + }, + { + "name": "bit32.btest", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.btest", + "heading": "bit32.btest (···)", + "markdown": "Returns a boolean signaling whether the bitwise *and* of its operands is different from zero.", + "plaintext": "Returns a boolean signaling whether the bitwise and of its operands is different from zero." + }, + { + "name": "bit32.bxor", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.bxor", + "heading": "bit32.bxor (···)", + "markdown": "Returns the bitwise *exclusive or* of its operands.", + "plaintext": "Returns the bitwise exclusive or of its operands." + }, + { + "name": "bit32.extract", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.extract", + "heading": "bit32.extract (n, field [, width])", + "markdown": "Returns the unsigned number formed by the bits `field` to `field + width - 1` from `n`. Bits are numbered from 0 (least significant) to 31 (most significant). All accessed bits must be in the range *\\[0, 31\\]*.\n\nThe default for `width` is 1.", + "plaintext": "Returns the unsigned number formed by the bits field to field + width - 1 from n. Bits are numbered from 0 (least significant) to 31 (most significant). All accessed bits must be in the range [0, 31].\n\nThe default for width is 1." + }, + { + "name": "bit32.replace", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.replace", + "heading": "bit32.replace (n, v, field [, width])", + "markdown": "Returns a copy of `n` with the bits `field` to `field + width - 1` replaced by the value `v`. See [`bit32.extract`](https://www.lua.org/manual/5.2/manual.html#pdf-bit32.extract) for details about `field` and `width`.", + "plaintext": "Returns a copy of n with the bits field to field + width - 1 replaced by the value v. See bit32.extract (https://www.lua.org/manual/5.2/manual.html#pdf-bit32.extract) for details about field and width." + }, + { + "name": "bit32.lrotate", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.lrotate", + "heading": "bit32.lrotate (x, disp)", + "markdown": "Returns the number `x` rotated `disp` bits to the left. The number `disp` may be any representable integer.\n\nFor any valid displacement, the following identity holds:\n\n```\n assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))\n```\n\nIn particular, negative displacements rotate to the right.", + "plaintext": "Returns the number x rotated disp bits to the left. The number disp may be any representable integer.\n\nFor any valid displacement, the following identity holds:\n\n assert(bit32.lrotate(x, disp) == bit32.lrotate(x, disp % 32))\n\nIn particular, negative displacements rotate to the right." + }, + { + "name": "bit32.lshift", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.lshift", + "heading": "bit32.lshift (x, disp)", + "markdown": "Returns the number `x` shifted `disp` bits to the left. The number `disp` may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\n\nFor positive displacements, the following equality holds:\n\n```\n assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)\n```", + "plaintext": "Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\n\nFor positive displacements, the following equality holds:\n\n assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)" + }, + { + "name": "bit32.rrotate", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.rrotate", + "heading": "bit32.rrotate (x, disp)", + "markdown": "Returns the number `x` rotated `disp` bits to the right. The number `disp` may be any representable integer.\n\nFor any valid displacement, the following identity holds:\n\n```\n assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))\n```\n\nIn particular, negative displacements rotate to the left.", + "plaintext": "Returns the number x rotated disp bits to the right. The number disp may be any representable integer.\n\nFor any valid displacement, the following identity holds:\n\n assert(bit32.rrotate(x, disp) == bit32.rrotate(x, disp % 32))\n\nIn particular, negative displacements rotate to the left." + }, + { + "name": "bit32.rshift", + "kind": "function", + "section": "6.7", + "anchor": "pdf-bit32.rshift", + "heading": "bit32.rshift (x, disp)", + "markdown": "Returns the number `x` shifted `disp` bits to the right. The number `disp` may be any representable integer. Negative displacements shift to the left. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\n\nFor positive displacements, the following equality holds:\n\n```\n assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))\n```\n\nThis shift operation is what is called logical shift.", + "plaintext": "Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).\n\nFor positive displacements, the following equality holds:\n\n assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))\n\nThis shift operation is what is called logical shift." + }, + { + "name": "debug", + "kind": "module", + "section": "6.10", + "anchor": "6.10", + "heading": "debug", + "markdown": "This library provides the functionality of the debug interface ([§4.9](https://www.lua.org/manual/5.2/manual.html#4.9)) to Lua programs. You should exert care when using this library. Several of its functions violate basic assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside; that userdata metatables cannot be changed by Lua code; that Lua programs do not crash) and therefore can compromise otherwise secure code. Moreover, some functions in this library may be slow.\n\nAll functions in this library are provided inside the `debug` table. All functions that operate over a thread have an optional first argument which is the thread to operate over. The default is always the current thread.", + "plaintext": "This library provides the functionality of the debug interface (§4.9 (https://www.lua.org/manual/5.2/manual.html#4.9)) to Lua programs. You should exert care when using this library. Several of its functions violate basic assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside; that userdata metatables cannot be changed by Lua code; that Lua programs do not crash) and therefore can compromise otherwise secure code. Moreover, some functions in this library may be slow.\n\nAll functions in this library are provided inside the debug table. All functions that operate over a thread have an optional first argument which is the thread to operate over. The default is always the current thread." + }, + { + "name": "debug.debug", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.debug", + "heading": "debug.debug ()", + "markdown": "Enters an interactive mode with the user, running each string that the user enters. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. A line containing only the word `cont` finishes this function, so that the caller continues its execution.\n\nNote that commands for `debug.debug` are not lexically nested within any function and so have no direct access to local variables.", + "plaintext": "Enters an interactive mode with the user, running each string that the user enters. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. A line containing only the word cont finishes this function, so that the caller continues its execution.\n\nNote that commands for debug.debug are not lexically nested within any function and so have no direct access to local variables." + }, + { + "name": "debug.gethook", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.gethook", + "heading": "debug.gethook ([thread])", + "markdown": "Returns the current hook settings of the thread, as three values: the current hook function, the current hook mask, and the current hook count (as set by the [`debug.sethook`](https://www.lua.org/manual/5.2/manual.html#pdf-debug.sethook) function).", + "plaintext": "Returns the current hook settings of the thread, as three values: the current hook function, the current hook mask, and the current hook count (as set by the debug.sethook (https://www.lua.org/manual/5.2/manual.html#pdf-debug.sethook) function)." + }, + { + "name": "debug.getinfo", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getinfo", + "heading": "debug.getinfo ([thread,] f [, what])", + "markdown": "Returns a table with information about a function. You can give the function directly or you can give a number as the value of `f`, which means the function running at level `f` of the call stack of the given thread: level 0 is the current function (`getinfo` itself); level 1 is the function that called `getinfo` (except for tail calls, which do not count on the stack); and so on. If `f` is a number larger than the number of active functions, then `getinfo` returns **nil**.\n\nThe returned table can contain all the fields returned by [`lua_getinfo`](https://www.lua.org/manual/5.2/manual.html#lua_getinfo), with the string `what` describing which fields to fill in. The default for `what` is to get all information available, except the table of valid lines. If present, the option '`f`' adds a field named `func` with the function itself. If present, the option '`L`' adds a field named `activelines` with the table of valid lines.\n\nFor instance, the expression `debug.getinfo(1,\"n\").name` returns a table with a name for the current function, if a reasonable name can be found, and the expression `debug.getinfo(print)` returns a table with all available information about the [`print`](https://www.lua.org/manual/5.2/manual.html#pdf-print) function.", + "plaintext": "Returns a table with information about a function. You can give the function directly or you can give a number as the value of f, which means the function running at level f of the call stack of the given thread: level 0 is the current function (getinfo itself); level 1 is the function that called getinfo (except for tail calls, which do not count on the stack); and so on. If f is a number larger than the number of active functions, then getinfo returns nil.\n\nThe returned table can contain all the fields returned by lua_getinfo (https://www.lua.org/manual/5.2/manual.html#lua_getinfo), with the string what describing which fields to fill in. The default for what is to get all information available, except the table of valid lines. If present, the option 'f' adds a field named func with the function itself. If present, the option 'L' adds a field named activelines with the table of valid lines.\n\nFor instance, the expression debug.getinfo(1,\"n\").name returns a table with a name for the current function, if a reasonable name can be found, and the expression debug.getinfo(print) returns a table with all available information about the print (https://www.lua.org/manual/5.2/manual.html#pdf-print) function." + }, + { + "name": "debug.getlocal", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getlocal", + "heading": "debug.getlocal ([thread,] f, local)", + "markdown": "This function returns the name and the value of the local variable with index `local` of the function at level `f` of the stack. This function accesses not only explicit local variables, but also parameters, temporaries, etc.\n\nThe first parameter or local variable has index 1, and so on, until the last active variable. Negative indices refer to vararg parameters; -1 is the first vararg parameter. The function returns **nil** if there is no variable with the given index, and raises an error when called with a level out of range. (You can call [`debug.getinfo`](https://www.lua.org/manual/5.2/manual.html#pdf-debug.getinfo) to check whether the level is valid.)\n\nVariable names starting with '`(`' (open parenthesis) represent internal variables (loop control variables, temporaries, varargs, and C function locals).\n\nThe parameter `f` may also be a function. In that case, `getlocal` returns only the name of function parameters.", + "plaintext": "This function returns the name and the value of the local variable with index local of the function at level f of the stack. This function accesses not only explicit local variables, but also parameters, temporaries, etc.\n\nThe first parameter or local variable has index 1, and so on, until the last active variable. Negative indices refer to vararg parameters; -1 is the first vararg parameter. The function returns nil if there is no variable with the given index, and raises an error when called with a level out of range. (You can call debug.getinfo (https://www.lua.org/manual/5.2/manual.html#pdf-debug.getinfo) to check whether the level is valid.)\n\nVariable names starting with '(' (open parenthesis) represent internal variables (loop control variables, temporaries, varargs, and C function locals).\n\nThe parameter f may also be a function. In that case, getlocal returns only the name of function parameters." + }, + { + "name": "debug.getmetatable", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getmetatable", + "heading": "debug.getmetatable (value)", + "markdown": "Returns the metatable of the given `value` or **nil** if it does not have a metatable.", + "plaintext": "Returns the metatable of the given value or nil if it does not have a metatable." + }, + { + "name": "debug.getregistry", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getregistry", + "heading": "debug.getregistry ()", + "markdown": "Returns the registry table (see [§4.5](https://www.lua.org/manual/5.2/manual.html#4.5)).", + "plaintext": "Returns the registry table (see §4.5 (https://www.lua.org/manual/5.2/manual.html#4.5))." + }, + { + "name": "debug.getupvalue", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getupvalue", + "heading": "debug.getupvalue (f, up)", + "markdown": "This function returns the name and the value of the upvalue with index `up` of the function `f`. The function returns **nil** if there is no upvalue with the given index.", + "plaintext": "This function returns the name and the value of the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index." + }, + { + "name": "debug.getuservalue", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.getuservalue", + "heading": "debug.getuservalue (u)", + "markdown": "Returns the Lua value associated to `u`. If `u` is not a userdata, returns **nil**.", + "plaintext": "Returns the Lua value associated to u. If u is not a userdata, returns nil." + }, + { + "name": "debug.sethook", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.sethook", + "heading": "debug.sethook ([thread,] hook, mask [, count])", + "markdown": "Sets the given function as a hook. The string `mask` and the number `count` describe when the hook will be called. The string mask may have any combination of the following characters, with the given meaning:\n\n- **'`c`':** the hook is called every time Lua calls a function;\n- **'`r`':** the hook is called every time Lua returns from a function;\n- **'`l`':** the hook is called every time Lua enters a new line of code.\n\nMoreover, with a `count` different from zero, the hook is called also after every `count` instructions.\n\nWhen called without arguments, [`debug.sethook`](https://www.lua.org/manual/5.2/manual.html#pdf-debug.sethook) turns off the hook.\n\nWhen the hook is called, its first parameter is a string describing the event that has triggered its call: `\"call\"` (or `\"tail call\"`), `\"return\"`, `\"line\"`, and `\"count\"`. For line events, the hook also gets the new line number as its second parameter. Inside a hook, you can call `getinfo` with level 2 to get more information about the running function (level 0 is the `getinfo` function, and level 1 is the hook function).", + "plaintext": "Sets the given function as a hook. The string mask and the number count describe when the hook will be called. The string mask may have any combination of the following characters, with the given meaning:\n\n- 'c': the hook is called every time Lua calls a function;\n- 'r': the hook is called every time Lua returns from a function;\n- 'l': the hook is called every time Lua enters a new line of code.\n\nMoreover, with a count different from zero, the hook is called also after every count instructions.\n\nWhen called without arguments, debug.sethook (https://www.lua.org/manual/5.2/manual.html#pdf-debug.sethook) turns off the hook.\n\nWhen the hook is called, its first parameter is a string describing the event that has triggered its call: \"call\" (or \"tail call\"), \"return\", \"line\", and \"count\". For line events, the hook also gets the new line number as its second parameter. Inside a hook, you can call getinfo with level 2 to get more information about the running function (level 0 is the getinfo function, and level 1 is the hook function)." + }, + { + "name": "debug.setlocal", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.setlocal", + "heading": "debug.setlocal ([thread,] level, local, value)", + "markdown": "This function assigns the value `value` to the local variable with index `local` of the function at level `level` of the stack. The function returns **nil** if there is no local variable with the given index, and raises an error when called with a `level` out of range. (You can call `getinfo` to check whether the level is valid.) Otherwise, it returns the name of the local variable.\n\nSee [`debug.getlocal`](https://www.lua.org/manual/5.2/manual.html#pdf-debug.getlocal) for more information about variable indices and names.", + "plaintext": "This function assigns the value value to the local variable with index local of the function at level level of the stack. The function returns nil if there is no local variable with the given index, and raises an error when called with a level out of range. (You can call getinfo to check whether the level is valid.) Otherwise, it returns the name of the local variable.\n\nSee debug.getlocal (https://www.lua.org/manual/5.2/manual.html#pdf-debug.getlocal) for more information about variable indices and names." + }, + { + "name": "debug.setmetatable", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.setmetatable", + "heading": "debug.setmetatable (value, table)", + "markdown": "Sets the metatable for the given `value` to the given `table` (which can be **nil**). Returns `value`.", + "plaintext": "Sets the metatable for the given value to the given table (which can be nil). Returns value." + }, + { + "name": "debug.setupvalue", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.setupvalue", + "heading": "debug.setupvalue (f, up, value)", + "markdown": "This function assigns the value `value` to the upvalue with index `up` of the function `f`. The function returns **nil** if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue.", + "plaintext": "This function assigns the value value to the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue." + }, + { + "name": "debug.setuservalue", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.setuservalue", + "heading": "debug.setuservalue (udata, value)", + "markdown": "Sets the given `value` as the Lua value associated to the given `udata`. `value` must be a table or **nil**; `udata` must be a full userdata.\n\nReturns `udata`.", + "plaintext": "Sets the given value as the Lua value associated to the given udata. value must be a table or nil; udata must be a full userdata.\n\nReturns udata." + }, + { + "name": "debug.traceback", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.traceback", + "heading": "debug.traceback ([thread,] [message [, level]])", + "markdown": "If `message` is present but is neither a string nor **nil**, this function returns `message` without further processing. Otherwise, it returns a string with a traceback of the call stack. An optional `message` string is appended at the beginning of the traceback. An optional `level` number tells at which level to start the traceback (default is 1, the function calling `traceback`).", + "plaintext": "If message is present but is neither a string nor nil, this function returns message without further processing. Otherwise, it returns a string with a traceback of the call stack. An optional message string is appended at the beginning of the traceback. An optional level number tells at which level to start the traceback (default is 1, the function calling traceback)." + }, + { + "name": "debug.upvalueid", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.upvalueid", + "heading": "debug.upvalueid (f, n)", + "markdown": "Returns an unique identifier (as a light userdata) for the upvalue numbered `n` from the given function.\n\nThese unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue (that is, that access a same external local variable) will return identical ids for those upvalue indices.", + "plaintext": "Returns an unique identifier (as a light userdata) for the upvalue numbered n from the given function.\n\nThese unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue (that is, that access a same external local variable) will return identical ids for those upvalue indices." + }, + { + "name": "debug.upvaluejoin", + "kind": "function", + "section": "6.10", + "anchor": "pdf-debug.upvaluejoin", + "heading": "debug.upvaluejoin (f1, n1, f2, n2)", + "markdown": "Make the `n1`-th upvalue of the Lua closure `f1` refer to the `n2`-th upvalue of the Lua closure `f2`.", + "plaintext": "Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2." + } + ] +} diff --git a/docs/CHANGELOG.vsix.md b/docs/CHANGELOG.vsix.md index 5f6fb78..e47274f 100644 --- a/docs/CHANGELOG.vsix.md +++ b/docs/CHANGELOG.vsix.md @@ -33,6 +33,11 @@ versions with an **even** middle number (for example 1.**2**.0) are stable relea - **Go to Symbol in Workspace** (Ctrl+T) finds functions, variables and menus in every Lua and `.menu` file of your workspace, even files you haven't opened. Files hidden with *Files: Exclude* are left out. +- **Documentation on hover.** Hover over a Lua function such as `string.format` to read its + description from the Lua 5.2 manual, over an EEex or game function such as + `Infinity_DisplayString` for a link to its EEex documentation, or over your own variables to + see how they are declared. Only the libraries the game provides are documented, and `print` + tells you that the game replaces it. - **Available in 14 languages**, following your VS Code display language. - **Works in other editors too**: setup guides for Sublime Text, Neovim, Emacs, JetBrains IDEs, Helix, Zed, Kate, Notepad++ and Geany are on the project page. diff --git a/docs/editors/README.md b/docs/editors/README.md index 078c4c4..e0ef1b7 100644 --- a/docs/editors/README.md +++ b/docs/editors/README.md @@ -68,6 +68,7 @@ node /path/to/server.js --stdio | Go to definition | `textDocument/definition` | The declaration of a local, or every assignment to a global, in the same file. | | Find references | `textDocument/references` | Every use of a local or global in the same file. | | Rename | `textDocument/prepareRename`, `textDocument/rename` | Same file only; refused, with the reason as the error message, when the rename could change what the code does. | +| Hover | `textDocument/hover` | Markdown or plain text, whichever the editor prefers (`hover.contentFormat`); the server's own words follow the editor's `locale`. See below. | | Workspace symbols | `workspace/symbol` | Every `*.lua` and `*.menu` file under the workspace folders, plus open files. See below. | Workspace symbols need an editor that sends **workspace folders** when it starts the server; @@ -80,6 +81,13 @@ through `workspace/configuration` (your guide says whether it does), you can add `ieLua`, for example `{ "files": { "exclude": { "**/backup": true } } }`. Only folders on the local disk are scanned. -Symbols, folding and navigation always reflect the current text, whatever `validate.mode` is. +Hover shows the [Lua 5.2 manual](https://www.lua.org/manual/5.2/manual.html) text for the +libraries the game provides, a link to the EEex documentation for EEex and game functions, and +how your own variables are declared. Editors that render Markdown get code blocks and links; +others get plain text with the links written out. The few words of the server's own (such as +`parameter`) are translated when the editor sends a `locale` the extension supports (one of the +14 VS Code display languages, or its language alone: `de-AT` uses German); otherwise English. + +Symbols, folding, hover and navigation always reflect the current text, whatever `validate.mode` is. Navigation works on variables: table fields (`t.x`) and `goto` labels are not followed, and in a `.menu` file globals are shared by all its Lua, while locals stay in their own block or script. diff --git a/l10n/server/messages.cs.json b/l10n/server/messages.cs.json new file mode 100644 index 0000000..fef2b14 --- /dev/null +++ b/l10n/server/messages.cs.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parametr", + "hover.kind.forVariable": "proměnná for", + "hover.kind.global": "globální", + "hover.engineReplaced": "Herní engine nahrazuje {0} vlastní funkcí, takže popis v příručce Lua 5.2 neplatí. Viz {1}." +} diff --git a/l10n/server/messages.de.json b/l10n/server/messages.de.json new file mode 100644 index 0000000..b9d35a2 --- /dev/null +++ b/l10n/server/messages.de.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "Parameter", + "hover.kind.forVariable": "for-Variable", + "hover.kind.global": "global", + "hover.engineReplaced": "Die Spiel-Engine ersetzt {0} durch eine eigene Funktion, daher gilt die Beschreibung im Lua 5.2-Handbuch nicht. Siehe {1}." +} diff --git a/l10n/server/messages.es.json b/l10n/server/messages.es.json new file mode 100644 index 0000000..bdf6523 --- /dev/null +++ b/l10n/server/messages.es.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parámetro", + "hover.kind.forVariable": "variable for", + "hover.kind.global": "global", + "hover.engineReplaced": "El motor del juego reemplaza {0} por una función propia, por lo que la descripción del manual de Lua 5.2 no se aplica. Consulte {1}." +} diff --git a/l10n/server/messages.fr.json b/l10n/server/messages.fr.json new file mode 100644 index 0000000..6eacce5 --- /dev/null +++ b/l10n/server/messages.fr.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "paramètre", + "hover.kind.forVariable": "variable for", + "hover.kind.global": "globale", + "hover.engineReplaced": "Le moteur du jeu remplace {0} par sa propre fonction : la description du manuel Lua 5.2 ne s'applique donc pas. Voir {1}." +} diff --git a/l10n/server/messages.hu.json b/l10n/server/messages.hu.json new file mode 100644 index 0000000..474e42c --- /dev/null +++ b/l10n/server/messages.hu.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "paraméter", + "hover.kind.forVariable": "for-változó", + "hover.kind.global": "globális", + "hover.engineReplaced": "A játékmotor saját függvényre cseréli a(z) {0} függvényt, ezért a Lua 5.2 kézikönyv leírása nem érvényes. Lásd: {1}." +} diff --git a/l10n/server/messages.it.json b/l10n/server/messages.it.json new file mode 100644 index 0000000..18cd307 --- /dev/null +++ b/l10n/server/messages.it.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parametro", + "hover.kind.forVariable": "variabile for", + "hover.kind.global": "globale", + "hover.engineReplaced": "Il motore di gioco sostituisce {0} con una propria funzione, quindi la descrizione del manuale di Lua 5.2 non si applica. Vedere {1}." +} diff --git a/l10n/server/messages.ja.json b/l10n/server/messages.ja.json new file mode 100644 index 0000000..b248938 --- /dev/null +++ b/l10n/server/messages.ja.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "パラメーター", + "hover.kind.forVariable": "for 変数", + "hover.kind.global": "グローバル", + "hover.engineReplaced": "ゲーム エンジンは {0} を独自の関数に置き換えるため、Lua 5.2 マニュアルの説明は当てはまりません。{1} を参照してください。" +} diff --git a/l10n/server/messages.json b/l10n/server/messages.json new file mode 100644 index 0000000..ff04bbc --- /dev/null +++ b/l10n/server/messages.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parameter", + "hover.kind.forVariable": "for variable", + "hover.kind.global": "global", + "hover.engineReplaced": "The game engine replaces {0} with its own function, so the description in the Lua 5.2 manual does not apply. See {1}." +} diff --git a/l10n/server/messages.ko.json b/l10n/server/messages.ko.json new file mode 100644 index 0000000..83b0160 --- /dev/null +++ b/l10n/server/messages.ko.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "매개 변수", + "hover.kind.forVariable": "for 변수", + "hover.kind.global": "전역", + "hover.engineReplaced": "게임 엔진이 {0}을(를) 자체 함수로 대체하므로 Lua 5.2 설명서의 설명은 적용되지 않습니다. {1}을(를) 참조하세요." +} diff --git a/l10n/server/messages.pl.json b/l10n/server/messages.pl.json new file mode 100644 index 0000000..2510399 --- /dev/null +++ b/l10n/server/messages.pl.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parametr", + "hover.kind.forVariable": "zmienna for", + "hover.kind.global": "globalna", + "hover.engineReplaced": "Silnik gry zastępuje {0} własną funkcją, więc opis z podręcznika Lua 5.2 nie ma zastosowania. Zobacz {1}." +} diff --git a/l10n/server/messages.pt-br.json b/l10n/server/messages.pt-br.json new file mode 100644 index 0000000..c8d52c0 --- /dev/null +++ b/l10n/server/messages.pt-br.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parâmetro", + "hover.kind.forVariable": "variável for", + "hover.kind.global": "global", + "hover.engineReplaced": "O mecanismo do jogo substitui {0} por uma função própria, portanto a descrição do manual do Lua 5.2 não se aplica. Consulte {1}." +} diff --git a/l10n/server/messages.ru.json b/l10n/server/messages.ru.json new file mode 100644 index 0000000..29538c3 --- /dev/null +++ b/l10n/server/messages.ru.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "параметр", + "hover.kind.forVariable": "переменная for", + "hover.kind.global": "глобальная", + "hover.engineReplaced": "Игровой движок заменяет {0} собственной функцией, поэтому описание из руководства по Lua 5.2 не применимо. См. {1}." +} diff --git a/l10n/server/messages.tr.json b/l10n/server/messages.tr.json new file mode 100644 index 0000000..7c0f086 --- /dev/null +++ b/l10n/server/messages.tr.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "parametre", + "hover.kind.forVariable": "for değişkeni", + "hover.kind.global": "global", + "hover.engineReplaced": "Oyun motoru {0} işlevini kendi işleviyle değiştirir; bu nedenle Lua 5.2 kılavuzundaki açıklama geçerli değildir. Bkz. {1}." +} diff --git a/l10n/server/messages.zh-cn.json b/l10n/server/messages.zh-cn.json new file mode 100644 index 0000000..225af1c --- /dev/null +++ b/l10n/server/messages.zh-cn.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "参数", + "hover.kind.forVariable": "for 变量", + "hover.kind.global": "全局", + "hover.engineReplaced": "游戏引擎将 {0} 替换为自己的函数,因此 Lua 5.2 手册中的说明不适用。请参阅 {1}。" +} diff --git a/l10n/server/messages.zh-tw.json b/l10n/server/messages.zh-tw.json new file mode 100644 index 0000000..3c183af --- /dev/null +++ b/l10n/server/messages.zh-tw.json @@ -0,0 +1,6 @@ +{ + "hover.kind.parameter": "參數", + "hover.kind.forVariable": "for 變數", + "hover.kind.global": "全域", + "hover.engineReplaced": "遊戲引擎會以自己的函式取代 {0},因此 Lua 5.2 手冊中的說明不適用。請參閱 {1}。" +} diff --git a/package.json b/package.json index f5474e7..93e72c8 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "test": "vscode-test", "check-l10n": "node scripts/check-l10n.mts", "build:wasm": "node third_party/lua52/build.mts", + "lua-manual": "node scripts/lua-manual/generate.mts", "notices": "node scripts/third-party-notices.mts" }, "dependencies": { diff --git a/scripts/check-l10n.mts b/scripts/check-l10n.mts index 0ab6715..a59e5de 100644 --- a/scripts/check-l10n.mts +++ b/scripts/check-l10n.mts @@ -2,23 +2,27 @@ // one GitHub annotation per problem, naming the file and key at fault. // // Checks: -// 1. Every VS Code display language has package.nls..json and -// l10n/bundle.l10n..json. +// 1. Every VS Code display language (src/shared/locales.ts) has +// package.nls..json, l10n/bundle.l10n..json and +// l10n/server/messages..json. // 2. Each locale has exactly the keys of the English source, all non-empty. // 3. Code spans (`…`, which include setting links), {0}-style placeholders and // **IE Lua: ** references survive translation unchanged // (references must use that locale's own command title). // 4. Every %key% used in package.json exists in package.nls.json and vice versa. // 5. l10n/bundle.l10n.json equals a fresh `@vscode/l10n-dev export` of src/client. +// The language server is not part of the export: it uses `messages.t()` +// (src/server/l10n.ts), not `vscode.l10n.t()`. +// 6. The server tables l10n/server/messages..json have exactly the keys +// of l10n/server/messages.json, with code spans and placeholders unchanged. +// 7. Every key of l10n/server/messages.json is used in src/server/ (as a +// quoted string); unknown keys are compile errors there (`MessageKey`). import { execFileSync } from 'node:child_process'; -import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; +import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { dirname, join, relative, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; - -// The display languages VS Code offers as language packs, besides English: -// https://code.visualstudio.com/docs/configure/locales#_available-locales -export const LOCALES = ['cs', 'de', 'es', 'fr', 'hu', 'it', 'ja', 'ko', 'pl', 'pt-br', 'ru', 'tr', 'zh-cn', 'zh-tw'] as const; +import { LOCALES } from '../src/shared/locales.ts'; const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const errors: string[] = []; @@ -130,6 +134,32 @@ if (packageNls && bundle) { } } +// 6. Language server tables. +const serverDir = join(root, 'l10n', 'server'); +const serverFile = join(serverDir, 'messages.json'); +const server = readJson(serverFile); +if (server) { + for (const locale of LOCALES) { + const localeFile = join(serverDir, `messages.${locale}.json`); + const translated = readJson(localeFile); + if (translated) { + compare(server, serverFile, translated, localeFile); + } + } + + // 7. Every server key is used by the server. + const sources = (dir: string): string[] => + readdirSync(dir, { withFileTypes: true }).flatMap((entry) => + entry.isDirectory() ? sources(join(dir, entry.name)) : entry.name.endsWith('.ts') ? [readFileSync(join(dir, entry.name), 'utf8')] : [], + ); + const serverSource = sources(join(root, 'src', 'server')).join('\n'); + for (const key of Object.keys(server)) { + if (!serverSource.includes(`'${key}'`)) { + error(serverFile, `"${key}" is not used in src/server; remove it from every l10n/server/messages*.json.`); + } + } +} + if (errors.length > 0) { for (const line of errors) { console.error(line); @@ -137,4 +167,7 @@ if (errors.length > 0) { console.error(`Localization check failed with ${errors.length} problem(s).`); process.exit(1); } -console.log(`Localization check passed: ${LOCALES.length} locales, ${Object.keys(packageNls ?? {}).length} manifest strings, ${Object.keys(bundle ?? {}).length} runtime strings.`); +console.log( + `Localization check passed: ${LOCALES.length} locales, ${Object.keys(packageNls ?? {}).length} manifest strings, ` + + `${Object.keys(bundle ?? {}).length} client strings, ${Object.keys(server ?? {}).length} server strings.`, +); diff --git a/scripts/lua-manual/convert.mts b/scripts/lua-manual/convert.mts new file mode 100644 index 0000000..ea9dba2 --- /dev/null +++ b/scripts/lua-manual/convert.mts @@ -0,0 +1,381 @@ +// Converts the HTML of the Lua 5.2 reference manual's library entries into +// Markdown and plain text, keeping the manual's wording and formatting. +// Pure: no I/O. Used by generate.mts. +// +// The manual (lua-5.2.4/doc/manual.html) is hand-written HTML 4 with a small +// vocabulary. This converter accepts exactly the subset the library entries +// use and throws on anything else, so a manual that changes shape fails the +// generator instead of producing silently wrong text: +// +//

starts a paragraph (it is never closed in the manual) +//

…
a code block, kept verbatim (an inside is shown +// without emphasis: code blocks cannot show it) +//
  • …
a list; items hold paragraphs and code blocks +// code span, emphasis, strong emphasis (an inside +// becomes an emphasized code span of its own) +// link into the manual, made absolute +// anchor, unwrapped +// superscript, as Unicode superscript characters +// (hovers render Markdown without HTML) +// +// Entities: only those the entries use, plus & and " (and ©, for +// the copyright line). + +/** Thrown for HTML outside the supported subset; the message says what and where. */ +export class UnsupportedHtmlError extends Error {} + +const ENTITIES: Readonly> = { + amp: '&', + quot: '"', + lt: '<', + gt: '>', + nbsp: '\u00a0', + middot: '\u00b7', + ndash: '\u2013', + sect: '\u00a7', + pi: '\u03c0', + // Only in the manual's copyright line, which generate.mts records. + copy: '\u00a9', +}; + +// Unicode has superscript forms for digits and some letters; only the +// characters the manual puts in are listed (2^32, 2^51, e^x, x^y, m2^e). +const SUPERSCRIPTS: Readonly> = { + '0': '\u2070', '1': '\u00b9', '2': '\u00b2', '3': '\u00b3', '4': '\u2074', + '5': '\u2075', '6': '\u2076', '7': '\u2077', '8': '\u2078', '9': '\u2079', + e: '\u1d49', x: '\u02e3', y: '\u02b8', +}; + +/** Replaces the supported character entities; throws on any other `&…;`. */ +export function decodeEntities(text: string): string { + return text.replace(/&([a-zA-Z0-9#]+);/g, (match, name: string) => { + const decoded = ENTITIES[name]; + if (decoded === undefined) { + throw new UnsupportedHtmlError(`Unsupported HTML entity ${match}.`); + } + return decoded; + }); +} + +// ------------------------------------------------------------------ tokens + +type Token = + | { readonly type: 'text'; readonly text: string } + | { readonly type: 'open'; readonly name: string; readonly attributes: Readonly>; readonly source: string } + | { readonly type: 'close'; readonly name: string; readonly source: string }; + +function tokenize(html: string): Token[] { + const tokens: Token[] = []; + const tag = /<(\/?)([a-zA-Z][a-zA-Z0-9]*)((?:\s+[a-zA-Z]+="[^"]*")*)\s*>/g; + let last = 0; + for (let match = tag.exec(html); match; match = tag.exec(html)) { + if (match.index > last) tokens.push({ type: 'text', text: html.slice(last, match.index) }); + const [source, slash, rawName = '', rawAttributes = ''] = match; + const name = rawName.toLowerCase(); + if (slash) { + tokens.push({ type: 'close', name, source }); + } else { + const attributes: Record = {}; + for (const [, key = '', value = ''] of rawAttributes.matchAll(/([a-zA-Z]+)="([^"]*)"/g)) attributes[key.toLowerCase()] = value; + tokens.push({ type: 'open', name, attributes, source }); + } + last = match.index + source.length; + } + if (last < html.length) tokens.push({ type: 'text', text: html.slice(last) }); + for (const token of tokens) { + if (token.type === 'text' && /[<>]/.test(token.text)) { + throw new UnsupportedHtmlError(`Unparsed markup in text: ${JSON.stringify(token.text.trim().slice(0, 60))}.`); + } + } + return tokens; +} + +// ------------------------------------------------------------------ tree + +type Inline = + | { readonly kind: 'text'; readonly text: string } + /** Code; `emphasized` parts are placeholders (`%d` in `string.gsub`). */ + | { readonly kind: 'code'; readonly parts: readonly { readonly text: string; readonly emphasized: boolean }[] } + | { readonly kind: 'em' | 'strong' | 'sup'; readonly children: readonly Inline[] } + | { readonly kind: 'link'; readonly fragment: string; readonly children: readonly Inline[] }; + +type Block = + | { readonly kind: 'paragraph'; readonly children: readonly Inline[] } + | { readonly kind: 'pre'; readonly text: string } + | { readonly kind: 'list'; readonly items: readonly (readonly Block[])[] }; + +class Parser { + private index = 0; + private readonly tokens: readonly Token[]; + constructor(tokens: readonly Token[]) { + this.tokens = tokens; + } + + /** Blocks until the end of input, or until `` (consumed). */ + blocks(until?: string): Block[] { + const blocks: Block[] = []; + let paragraph: Inline[] = []; + const flush = (): void => { + if (paragraph.some((inline) => inline.kind !== 'text' || inline.text.trim() !== '')) { + blocks.push({ kind: 'paragraph', children: paragraph }); + } + paragraph = []; + }; + for (;;) { + const token = this.tokens[this.index]; + if (!token) { + if (until) throw new UnsupportedHtmlError(`Missing .`); + break; + } + if (token.type === 'close' && token.name === until) { + this.index++; + break; + } + if (token.type === 'open' && token.name === 'p') { + this.index++; + flush(); + } else if (token.type === 'open' && token.name === 'pre') { + this.index++; + flush(); + blocks.push({ kind: 'pre', text: this.pre() }); + } else if (token.type === 'open' && token.name === 'ul') { + this.index++; + flush(); + blocks.push({ kind: 'list', items: this.listItems() }); + } else { + paragraph.push(...this.inline(token)); + } + } + flush(); + return blocks; + } + + /** + * The text of a `
`. `` marks placeholders in two examples
+   * (`for i,v in ipairs(t) do body end`); a code block cannot show
+   * emphasis, so its text is kept and the emphasis dropped.
+   */
+  private pre(): string {
+    let text = '';
+    for (;;) {
+      const token = this.tokens[this.index++];
+      if (token?.type === 'close' && token.name === 'pre') break;
+      if (token?.type === 'text') {
+        text += token.text;
+      } else if (token?.type === 'open' && token.name === 'em') {
+        const [inner, close] = [this.tokens[this.index], this.tokens[this.index + 1]];
+        if (inner?.type !== 'text' || close?.type !== 'close' || close.name !== 'em') {
+          throw new UnsupportedHtmlError(' in 
 must contain only text.');
+        }
+        text += inner.text;
+        this.index += 2;
+      } else {
+        throw new UnsupportedHtmlError(`
 must contain only text and , found ${token ? describe(token) : 'the end of input'}.`);
+      }
+    }
+    // HTML ignores a newline right after 
; the one before 
ends the last line. + return decodeEntities(text).replace(/^\r?\n/, '').replace(/\r?\n$/, ''); + } + + private listItems(): Block[][] { + const items: Block[][] = []; + for (;;) { + const token = this.tokens[this.index]; + if (!token) throw new UnsupportedHtmlError('Missing .'); + this.index++; + if (token.type === 'text' && token.text.trim() === '') continue; + if (token.type === 'close' && token.name === 'ul') return items; + if (token.type === 'open' && token.name === 'li') { + const item = this.blocks('li'); + if (item.some((block) => block.kind === 'list')) throw new UnsupportedHtmlError('Nested lists are not supported.'); + items.push(item); + continue; + } + throw new UnsupportedHtmlError(`Unexpected ${describe(token)} in