@gwigz/slua

Documentation

Shared runtime modules for SLua projects

Work in progress

These modules are under active development and have not been battle-tested in production. APIs may change between releases.

@gwigz/slua-modules is a set of reusable runtime modules for SLua projects. Modules are vendored, the CLI copies their TypeScript source directly into your project, so there is no package dependency and the code is yours to edit. Everything compiles to Lua through TypeScript-to-Lua, and @define flags strip whatever you did not enable.

Add modules

npx @gwigz/slua-modules add yield

Modules are copied into src/modules/ (or modules/ when your project has no src/ directory), pass --dir to override. Shared helpers land in an internal/ folder alongside the modules that use them. Run @gwigz/slua-modules list with npx, pnpm dlx, or bunx to see what is available.

Import from the vendored path, relative to your script:

import { spawn, dialog } from "./modules/yield"

Compile-time flags

Some modules use compile-time flags to strip unused code from the Lua output. Flags are set via the define option on @gwigz/slua-tstl-plugin in your tsconfig. When a flag is false (or omitted), the guarded code is removed entirely by dead code elimination.

tsconfig.json
{
  "tstl": {
    "luaPlugins": [
      {
        "name": "@gwigz/slua-tstl-plugin",
        "define": {
          "CONFIG_YAML_PARSER": true,
          "YIELD_DATASERVER_AGENT": true,
          "YIELD_HTTP": true,
        },
      },
    ],
  },
}

Only enable the flags you need, omitted flags default to false and their code is stripped. See each module's documentation for the available flags.

Flag-bearing modules ship a flags.d.ts next to their source, keep it in your tsconfig include (and any explicit build script file list), nothing imports it directly. The CLI prints the exact entries after add.

Modules

On this page