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.
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.@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.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.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.println output and component events in the console. Share a link to what
you build.fetch.551dcc08db500a4e5c7cbbbb1b34c561393059be36305d542f6a52dfd4a5b257)<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>
@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;
}