Skip to content
PytechNoPublic

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

Weblua

Weblua is a free, client-side playground for multi-file Lua 5.1, 5.2, 5.3, 5.4, 5.5, and Luau projects. Each run happens in a dedicated Web Worker through WebAssembly; there is no account system, code-execution backend, or project database.

Weblua is a language playground, not a Roblox emulator. Its Luau runtime accepts Luau language syntax, including annotations and generics, and its editor runs Luau's type checker, but it does not provide Roblox services, instances, globals, or Studio tooling.

What the playground includes

  • Lua 5.1, 5.2, 5.3, 5.4, 5.5, and Luau runtime selection per project.
  • An editor with Lua and Luau syntax highlighting, folding, and indentation from a Lezer grammar; completion and hover docs for the selected runtime's standard library, the file's own locals and table fields, Luau types, and require paths; and StyLua formatting with Shift+Alt+F.
  • Multi-file projects with a selectable entry file. Files with another extension (data.json, .luaurc) are project data: saved and shared, never compiled, and readable with io.open on Lua 5.4.
  • require("lib.module"), require("lib/module"), and init.lua module aliases. Luau also resolves ./, ../, and @self paths relative to the requiring module, and @alias paths from .luaurc files, for runs and for the type checker.
  • Compare: run the same project on a second runtime and see both outputs side by side, with a note when they differ.
  • Luau's task library (spawn, defer, delay, wait, cancel) with real-time waits.
  • A Check action that compiles every file without running it and reports per-file syntax diagnostics (and, for Luau, type errors and lints).
  • Luau type checking and linting as you type, in strict or nonstrict mode, with autocomplete and hover types.
  • A Luau bytecode view with optimization and debug levels.
  • Preset stdin through io.read() in Lua and read() in Luau.
  • Live stdout and stderr, with status and elapsed time after each run finishes. file:line locations in errors and Check results link to that line.
  • Source-only share links, GitHub gist links, and lazy-loading iframe embeds.
  • Recovery drafts and named projects stored in IndexedDB, with a save status, and Undo after Start over or deleting a file.
  • On phones: a key bar for undo, redo, indent, and the punctuation phone keyboards hide, plus text size and line-wrap settings.
  • Offline reopening through a service worker, once a page and its runtime have loaded online.
  • Source-only .weblua.json import and export.
  • Fifteen built-in examples, including a multi-file capability tour, a Luau task project, and a Luau project whose module exports types to the file that requires it.

Tool pages open the playground on one job, with a guide below the editor: /lua-formatter, /luau-type-checker, /luau-bytecode-viewer, /lua, and /luau. Two small tools have their own UI: a pattern tester that highlights every match and capture on the runtime you pick, with a cheat sheet whose examples load into it, and a Lua table to JSON converter that works both ways. The comparisons /lua-vs-luau and /lua-5-1-vs-5-4 are articles with both runtimes embedded side by side. /examples holds runnable examples with their output on Lua 5.1, 5.4, and Luau, and /learn-luau is an eight-lesson course: animated walkthroughs that step through code and show each variable change, predict-the-output quizzes, and an exercise per lesson in an embedded editor whose passing run marks the lesson done.

All of this text lives in src/lib/ (guidePages.ts, lessonPages.ts, examplePages.ts). src/workers/articles.execution.test.ts runs every code block, walkthrough, quiz, and exercise against the real runtimes and type-checks the Luau in strict mode, and src/lib/articles.test.ts keeps pages from going thin or linking to pages that don't exist. The build adds per-page JSON-LD and writes llms.txt.

Try the capability tour

Choose Multi-file capability tour from the Example menu. It demonstrates:

  • nested modules and init.lua resolution;
  • require caching;
  • a selected main.lua entry point;
  • preset line and whole-input reads; and
  • formatted output from several source files.

The same project is available as examples/weblua-capability-tour.weblua.json and can be loaded with the playground's Import project button.

Project execution model

Projects contain a runtime flavor, an entry path, and a map of normalized relative paths. Lua 5.4 mounts those files into Wasmoon's virtual filesystem and runs from the project folder, so chunk names, error messages, and io.open use project paths. Lua 5.1–5.3 and 5.5 register the same paths through package.preload. Luau compiles every source file and resolves modules through an in-VM browser-safe loader. That loader follows Luau's require-by-string rules: ./ and ../ resolve against the requiring module's folder (for an init.luau, the folder that contains it), @self/ against the module itself, and any other @alias through the nearest .luaurc in the requiring file's folder or above it. Alias paths are relative to their .luaurc; one that is not JSON fails the run and shows up in Check. Luau's entry module runs as the main thread of an in-VM task scheduler, so top-level code can task.wait; the run ends when no task is left waiting. An error in the main thread fails the run, while an error in any other task is printed to stderr and the remaining tasks keep running.

The Check action compiles every source file without running it. For Luau projects it also type-checks and lints them; see below.

Luau type checking

Luau projects are checked by Luau's own analyzer, compiled to WebAssembly by @luau-rs/luau. It runs in a separate worker that only loads for Luau projects (about 1.7 MB gzipped, fetched once and then cached), so Lua 5.x projects never download it.

  • The editor underlines type errors and lint warnings in the open file as you type. Check reports them for every project file.
  • The Types menu in the editor header sets the default mode: Strict, Nonstrict, or Off. A --!strict, --!nonstrict, or --!nocheck comment at the top of a file overrides it, and --!nolint silences lints. The choice is remembered per browser.
  • require resolves the same names the runtime accepts, including require("lib.util") and ./, ../, and @self paths, so types flow between project files.
  • Completion gains checked types, plus the fields and methods of values from other files. Hovering any name shows its type; stdlib names keep their documentation under it. Until the analyzer has loaded, both work from the syntax tree alone.
  • Weblua's read() and task globals are declared to the checker. Roblox globals are not.

The analyzer and the runtime are built from different Luau releases, so a newer syntax feature can pass one and not the other. The runtime's compile check always runs as well, and its verdict on syntax is the one that matters for Run.

Output is streamed from the worker as it is produced. The page batches display updates and keeps received output when a run is stopped or times out. Completed runs also return their full output with the final result.

Luau bytecode

In a Luau project, the output pane's Bytecode tab lists what Luau's compiler makes of the open file, and updates as you edit. The compiler is a second WebAssembly build from @luau-rs/luau (about 0.8 MB compressed), loaded in its own worker the first time the tab opens.

  • Optimize sets the level from 0 to 2. Level 2 inlines small local functions and folds constants, and REMARK lines in the listing say what it did.
  • Debug sets the debug info kept: 0 none, 1 line numbers and function names, 2 also local variable names, which the listing prints per function.
  • Source prints each source line above the instructions compiled from it.

Runs compile at optimization level 1. A --!optimize 0, 1, or 2 comment at the top of a file sets the level for that file's runs as well as its listing, and the Optimize menu shows when one does. The runtime offers no other compiler options, so the Debug menu only changes the listing.

The listing comes from the same Luau release as the type checker, which can differ from the runtime's, so small details may not match the bytecode a run executes.

Sharing, embeds, and persistence

Current share links encode a source-only project as /playground#c=2.... The map is compressed with browser-native CompressionStream using raw DEFLATE, then base64url-encoded into the fragment. The same payload is used by /embed#c=2.... URL fragments are not included in HTTP requests to the static host.

Share links and embeds include:

  • source files;
  • the selected entry file; and
  • the runtime flavor.

They deliberately exclude preset input, output, active editor state, named-project metadata, and IndexedDB records. Older #c=1... and #share= links still decode as one-file projects.

Encoded share payloads are limited to 32 KiB, which holds roughly 85 KB (about 2,500 lines) of typical source, typed Luau included. When a project is too large for a reliable URL, share it as a gist (below) or export its source as .weblua.json. Decompressed incoming share data is capped at 1 MiB before JSON parsing.

Gist links

A gist link is short whatever the project's size, which also suits chats that cap message length. Weblua has no backend that could create a gist, so:

  1. Export the project and add the .weblua.json file to a GitHub gist. Secret gists work.
  2. Share https://weblua.com/playground#gist=<gist id>, or /embed#gist=<gist id> for an iframe. Projects → Open gist accepts a gist URL or ID and puts that link in the address bar.

A gist of plain .lua or .luau files opens too, as a flat project (gist file names cannot contain folders): Luau if any file is .luau, otherwise Lua 5.4, with main, then init, as the entry. Use a .weblua.json export to keep folders, another Lua version, or a different entry.

Opening a gist link downloads the gist from GitHub's API in the visitor's browser, so GitHub sees that request; it allows 60 of them an hour from one address. Gist sources are capped at 1 MiB, like decompressed share data.

The browser stores the recovery draft and named project library in IndexedDB. If IndexedDB is unavailable, the editor falls back to non-persistent in-memory storage.

Runtime boundaries

  • Runs stop after five seconds -- thirty with long runs enabled -- by terminating the worker. Output is streamed to the page as it is produced, so a run that is stopped or times out still shows everything it printed.

  • Stop ends a run immediately, from the toolbar or with Esc.

  • Lua 5.4 has a 32 MiB runtime memory cap.

  • URL sharing has a 32 KiB encoded-payload cap; gist links do not.

  • The Luau runtime does not include Roblox APIs, and the type checker does not know Roblox types. Its task library is a language-level scheduler, not Roblox's engine loop.

  • task.wait uses real time with a one-frame (1/60 s) minimum, as on Roblox, so waits count toward the run's time limit.

  • The bytecode view lists Luau only; Lua 5.x runtimes have no listing.

  • Formatting loads StyLua's WebAssembly build (about 0.9 MB compressed) on first use. StyLua has no Lua 5.5 mode, so Lua 5.5 files are formatted as Lua 5.4 and code using 5.5-only syntax such as global reports a notice instead.

  • The virtual project filesystem only contains the files supplied to the run, and only Lua 5.4 exposes it to io.open.

  • print stringifies in the VM, as the real one does, so Lua 5.4 prints 3.0 and -0.0 and tables print as addresses. Uncaught and caught errors name project files (main.lua:3:), as the real interpreters do.

  • Lua 5.4's io.read override and Luau's read helper support *l, *L, and *a. Lua 5.1–5.3 and 5.5 receive the preset input through their standard byte-stream stdin.

  • Lua 5.4 routes print, io.write, io.stdout:write, and stderr writes through the captured result stream while retaining the native file handles.

These boundaries make Weblua suitable for examples, experiments, bug reproductions, and language comparisons—not long-running jobs or validation against a production Roblox environment.

Privacy and optional telemetry

Normal execution does not upload project source to a code-execution service. Sharing places source in a URL fragment only when the user requests a link or embed. Opening a #gist= link, or a gist from Projects, downloads that gist from api.github.com.

Deployments may optionally enable Plausible or Umami usage events and Sentry error reporting. The tracked product events contain fixed runtime/status, feature, public lesson/example, and button-placement metadata rather than source. They cover editor actions, local projects, standalone tools, learning progress, page reading, and outbound link hosts. Sentry is configured without default PII, and Weblua strips URL fragments and redacts #c=, #share=, and #gist= values from error events and navigation breadcrumbs before sending. Plausible is not loaded on a URL that contains a current or legacy source payload or a gist ID (the only key to a secret gist). Umami is told to drop URL fragments, which hold those values, from every page and referrer it reports. Umami also keeps only UTM campaign query parameters, removes same-site referrers, reduces external referrers to their origin, and collects Core Web Vitals on compatible versions. Telemetry runs in production builds only, honors Global Privacy Control and Do Not Track, and supports a persistent browser opt-out at /?analytics=off (/?analytics=on reverses it). See analytics setup, event definitions, and verification. Leave the environment variables unset to disable these integrations completely.

Browser requirements

Weblua targets current evergreen browsers with JavaScript, WebAssembly, module Web Workers, and modern URL APIs. Project sharing additionally needs CompressionStream/DecompressionStream; persistence needs IndexedDB; copying links and embeds needs the Clipboard API.

A service worker caches each page and hashed asset as it loads, and each runtime the first time a run fetches it. A page you have opened online, with a runtime you have run, reopens and runs offline. Pages and runtimes you have never loaded need a connection, and the GitHub gist loader always does.

Run locally

Node 22.12 or newer is recommended.

npm install
npm run dev

Open the local Vite URL. Press Ctrl/Cmd-Enter to run, Ctrl/Cmd-Shift-Enter to compile-check every file (and type-check it, for Luau), or Shift+Alt+F to format the open file.

The editor grammar lives in src/lang/lua/lua.grammar and is compiled by @lezer/generator's Vite plugin during dev, build, and tests. The standard-library catalog behind completion and hover, src/lang/lua/stdlib.ts, is checked against every runtime by stdlib.test.ts, so a runtime upgrade that adds or removes a name fails the suite until the catalog is updated.

Scripts

  • npm run dev starts the Vite development server.
  • npm run build type-checks, builds, writes static /playground, /embed, and tool-page (/lua-formatter, /luau-type-checker) entry pages, and prerenders the landing page.
  • npm run preview serves the production build locally.
  • npm test runs the project, codec, gist, persistence, routing, telemetry, editor language, stdlib catalog, formatter, Luau regression, Luau analysis, and Luau bytecode tests.

Docker and self-hosting

The included multi-stage Dockerfile builds the Vite app with Node 22 and npm 11 (the npm that writes package-lock.json) and serves the static output with nginx:

docker build -t weblua .
docker run --rm -p 8080:80 weblua

Open http://localhost:8080. The nginx configuration serves hashed assets with long-lived caching and provides route fallback for /playground, /embed, and the tool pages.

For a complete hosted deployment walkthrough, see docs/coolify-deployment.md.

Upstream notes: Luau web bridge

luau-web@1.4.0 auto-selects its JSPI build in browsers that expose WebAssembly.Suspending and WebAssembly.promising. In that build, Luau runtime errors can escape pcall/xpcall instead of returning false, message.

Weblua avoids that path in src/lib/luauWebAsyncify.ts by loading luau-web/src/lib/Luau.Web.Asyncify.js directly. Regression tests cover both pcall and xpcall and verify that execution continues after the protected error. This fixes Weblua's user-visible behavior, but it is a local workaround—not an upstream JSPI fix.

The Asyncify build has a separate teardown issue: native maps keyed by lua_State* survive luauClose. If the allocator reuses that pointer, a later state can receive stale registry references, fail with attempt to call a nil value, and eventually abort the WebAssembly instance. Weblua gives every LuauState an isolated Asyncify instance, making repeated execution in a long-lived worker safe at the cost of repeating Luau initialization.

The upstream JSPI target links with -fwasm-exceptions, while the protected-call implementation lives in the ordinary Luau.VM static library. A clean upstream fix would compile a separate Luau.VM.JSPI with native WebAssembly exceptions and link Luau.Web.JSPI against it. The prepared reproduction and proposed patch shape are in docs/luau-web-pcall-issue.md.

Once upstream publishes a fixed release, update luau-web, verify both protected call regressions in a JSPI-capable browser plus repeated state teardown, and remove the Asyncify-only wrapper.

Production hooks

Optional build-time environment variables:

VITE_PLAUSIBLE_DOMAIN=weblua.com
VITE_SENTRY_DSN=https://example@sentry.io/project

Both are optional and disabled when empty. Because Vite inlines them at build time, changing either value requires a rebuild. For Docker builds, pass them as build arguments, for example --build-arg VITE_PLAUSIBLE_DOMAIN=example.com.

License

Weblua is available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages