Getting Started
Set up a new project with TypeScript-to-Lua for Second Life
Scaffold a project
Start with the scaffolding CLI:
npx @gwigz/slua-createThis walks you through template selection, optional extras (JSX, vendored
modules, StyLua, linting), and generates a ready-to-build project. It can also
run non-interactively, e.g. npx @gwigz/slua-create my-project --yes, see
--help for all flags.
Manual setup
If you prefer to set things up yourself, install the packages directly:
npm install --save-dev typescript typescript-to-lua @gwigz/slua-types @gwigz/slua-tstl-pluginThen create a tsconfig.json in your project root:
{
"$schema": "https://raw.githubusercontent.com/TypeScriptToLua/TypeScriptToLua/master/tsconfig-schema.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"moduleDetection": "force",
"skipLibCheck": true,
"lib": ["ESNext"],
"types": ["@typescript-to-lua/language-extensions", "@gwigz/slua-types"],
"outDir": "out"
},
"tstl": {
"luaTarget": "Luau",
"luaLibImport": "inline",
"noImplicitSelf": true,
"noImplicitGlobalVariables": true,
"luaPlugins": [{ "name": "@gwigz/slua-tstl-plugin" }],
"extension": "slua"
}
}See the TSTL configuration docs for all available options.
This is a minimal setup that compiles each file on its own. Projects generated by
@gwigz/slua-create also bundle imports into a standalone script per entry point (via
luaBundle, @gwigz/tstl-bundle-flatten, and "luaLibImport": "require-minimal"), so prefer the
CLI if you want to split your code across modules.
Editor setup (optional)
Map .slua to Lua highlighting in VS Code:
{
"files.associations": {
"*.slua": "lua"
}
}Tell GitHub to highlight .slua files as Lua:
*.slua linguist-language=LuaYou may also like the Second Life SLua/LSL extension for additional language support.
Compile
npx tstlTo rebuild automatically whenever a file changes, pass --watch:
npx tstl --watchScaffolded projects wire this up as the dev script: npm run dev,
pnpm dev, or bun run dev.
Deploy
To get the compiled output in-world without copy-pasting it into the viewer, push it in-world over the viewer's external editor connection:
bun run build && bunx @gwigz/slua-viewer-client push dist/main.sluaCompile errors come back pointing at your TypeScript source. See @gwigz/slua-viewer-client.