Loup · WebWorks · Preview

WebWorks

WebWorks is the web toolkit that ships with Loup. It has three parts: a runtime that runs Loup in the browser, a library of 196 web components written in Loup, and a Loup web server that delivers both. You write the front end in Loup, the same language as the rest of your program.

What ships with Loup
The browser runtime
loup-rt.wasm is Loup's own front end and interpreter, compiled to WebAssembly, with the standard library built in. A page loads it once with the loup-web.js loader and then runs Loup source directly: from <script type="text/loup"> tags or from JavaScript. It uses only core WebAssembly (no garbage-collection, exception-handling or threads extensions), so it needs no special server headers.
Web modules for Loup
Programs in @mode(web.scripted) use the web standard-library modules: web.dom for elements, events, timers and fetch; web.storage for local storage; web.js to call JavaScript and be called from it; ui.web for reactive signals bound to the DOM; and web.components to define custom elements.
196 web components
The ww-* components are standard custom elements written in Loup: layouts, buttons, form fields, pickers, dialogs, menus, tabs, data tables, charts, editors and more. One layout element covers dock, grid, stack, split and the other layout techniques. Light, dark and high-contrast themes, accent colours and densities apply to any part of a page.
The WebWorks server
The webworks package is a Loup web server: routes with :param segments, JSON and static-file responses, and mountLoupRuntime, which serves your pages together with the runtime, with the right WebAssembly content type and gzip delivery.
Try it in your browser
Everything below runs Loup in your browser. The first visit downloads the runtime (about 2.5 MB compressed); after that the browser caches it.
Get the runtime
Download the runtime and its loader, put them next to your page, and run Loup:
Files
  • loup-rt.wasm (14.8 MB; SHA‑256 551dcc08db500a4e5c7cbbbb1b34c561393059be36305d542f6a52dfd4a5b257)
  • loup-rt.wasm.gz (2.5 MB, the same runtime compressed)
  • loup-web.js (the JavaScript loader)
Run Loup on a page
<script type="module">
  import { LoupRuntime } from "./loup-web.js";

  const rt = await LoupRuntime.load("./loup-rt.wasm", {
    onStdout: (text) => console.log(text),
  });
  rt.eval(`@mode(web.scripted)
println("Hello from Loup");`);
  await rt.runPageScripts();   // runs <script type="text/loup"> tags
</script>
Serve it from Loup
@mode(host.dual)
from net.http import (Request);
from webworks.web_server import (WebApp, WebResponse, ServerConfig);

func main(): int {
    var app = WebApp();
    safe {
        app.get("/api/echo/:msg", func(req: Request, params: dict[string, string]): WebResponse {
            return WebResponse.json("{\"echo\":\"" + params["msg"] + "\"}");
        });
        app.mountLoupRuntime("/", "site");   // your pages + loup-rt.wasm
    }
    app.serve(ServerConfig("127.0.0.1", 8080));
    return 0;
}
WebWorks is part of the Loup Preview: the runtime, the web modules and the component APIs may change from one release to the next. The runtime, the web modules and the components are covered by the Loup License, like the rest of Loup.
Build with Loup
Install Loup Lite to write Loup on your own machine, and read the Loup books to learn the language.