The Loup Web Book
⚠ Status: Loup 1.25.1, plus the browser runtime. This book describes the web design in the Loup Language Reference (the v1.20 volumes, amended in place through 1.25). Anything marked ⚠ Planned is not implemented yet. Loup code now runs in the browser:
loup-rt.wasm, the Loup interpreter compiled to WebAssembly, runs<script type="text/loup">blocks and provides theweb.dom,web.storage,web.js,web.componentsandui.webmodules. It is in the Loup source tree (source/testsites/) and not in a release archive yet (Chapter 1, "Running Loup in the browser"). The browser listings in chapters 1 and 16–18 were run in Chrome on it. The Reference's fuller design (loup-rt.jsforweb.compiledbuilds, the HTML shell,loup serve, theuimodule and fences,@webcomponent,extern js, workers, SSR) is still planned, and those parts of chapters 16–19 are design previews.
This book teaches Loup for the web: the two web execution modes,
web.compiled and web.scripted, and the language you write in them. It is
for people who build web front ends and services and want static types,
value types, explicit ownership and a single toolchain.
What works today, and what is planned
| Piece | Loup 1.25.1 |
|---|---|
The language in .lpweb files (@mode(web.compiled), @mode(web.scripted)) |
Works. loup run app.lpweb runs the file on the host interpreter. |
| Type-checking a project | Works. loup-bootstrap check |
Template fences (html, css, …) rendered to strings |
Works, but html fences do not auto-escape yet (Chapter 14). |
async / await |
Works, but an async call runs eagerly, to completion, when it is called; there is no task scheduler yet (Chapter 15). |
| Compiling to WebAssembly | Experimental, not audited. loup-bootstrap build --target browser writes one bare build/<name>.wasm, which runs under loup-launcher --run-bare. |
Running web.scripted code in the browser: loup-rt.wasm + loup-web.js, <script type="text/loup"> |
Works (Chrome and other browsers with Core WebAssembly). In the source tree, not in a release archive yet (Chapter 1). |
DOM, events, timers and fetch (web.dom); localStorage / sessionStorage (web.storage) |
Works in the browser runtime (Chapter 18) |
Signals, element builders and mount (ui.web); custom elements with a shadow root (web.components) |
Works in the browser runtime (chapters 16 and 17) |
Calling JavaScript and being called from it with string arguments (web.js) |
Works in the browser runtime (Chapter 18) |
loup-rt.js for web.compiled Wasm builds, generated HTML shell, loup serve |
⚠ Planned |
The ui module (signal, View, ui fences), @webcomponent classes |
⚠ Planned |
extern js, @jsexport, lang.interop.js, workers |
⚠ Planned |
| Server-side rendering, hydration, deployment layout | ⚠ Planned |
Known gaps in Loup 1.25.1
These are places where the toolchain does not yet do what the Language Reference specifies. The chapters show each one with real output where it comes up:
intarithmetic wraps on overflow instead of throwing (the sized types such asint32do throw).[1, 2] == [1, 2]isfalse: collection equality is not element-wise yet.- A
deferbody never runs; usetry/finallyfor cleanup. asyncfunctions run eagerly at the call; a failure surfaces at the call, not atawait.htmlfences do not escape interpolated values; use theescapefilter.panicis undefined in web code;throwan exception instead.- A
web.compiledfile cannot import any standard-library module (E_COMPILED_IMPORT_SCRIPTED);web.scriptedfiles can. - In Wasm builds,
i"…"interpolated strings,//andfor awaitstop the program at run time; the same code runs underloup runand in the browser runtime. - The browser runtime does not report type errors: a program the type
checker rejects prints nothing and
evalreturns exit code 0. Parse and import errors are reported (Chapter 1). - The browser runtime keeps the callbacks of one entry script per runtime instance. A second entry script on the page takes over the first one's event handlers, so put one entry script on a page and register the rest as modules (Chapter 1).
The two web modes
Every Loup file declares its execution mode on its first line. The web book
uses two modes, and web files use the .lpweb extension:
@mode(web.compiled)
func main(): void {
println("Hello from web.compiled");
}
Hello from web.compiled
Save it as hello.lpweb and run it with loup run hello.lpweb.
web.compiledis the browser's ahead-of-time mode. A file holds only declarations. The runner callsmain(), so that is where the program starts (Chapter 2).web.scriptedis the browser's just-in-time mode. Its top-level statements run in order, like a script.
The names @mode(compiled) and @mode(scripted) that older Loup material
uses were retired in v1.17. The compiler does not reject them; it silently
runs the file as host.scripted, so a web.compiled program written with
the old name never calls main() and prints nothing. Always write the full
mode name.
Installing Loup
The official builds are published on the
code-craft-ai-company/loup-releases
GitHub releases:
# Linux and macOS
curl -fsSL https://github.com/code-craft-ai-company/loup-releases/releases/latest/download/loup-install.sh | sh
# Windows (PowerShell)
irm https://github.com/code-craft-ai-company/loup-releases/releases/latest/download/loup-install.ps1 | iex
The installer puts the toolchain in ~/.loup (or
%LOCALAPPDATA%\Programs\Loup on Windows) and adds its bin directory to
your PATH. To pin a version, use sh -s -- --version 1.25.1 or set
LOUP_VERSION. Every archive contains loup, loup-bootstrap (the compiler
that builds Wasm) and loup-launcher (the Wasm runtime). Chapter 1 walks
through the first project.
Where this book fits
There are four Loup books, one per environment:
| Book | Modes |
|---|---|
| The Loup Scripting Book | host.scripted, host.dual |
| The Loup Web Book (this book) | web.compiled, web.scripted |
| The Loup Native Book | host.native, host.dual |
| The Loup Freestanding Book | freestanding |
The language is the same in every mode; what changes is the entry point, which features are available, and how the program is delivered. Chapters 3 to 13 of this book teach the core language, so you can read them without the other books.
How to read this book
Chapters 1 and 2 cover the toolchain and the rules of the two web modes. Chapters 3 to 13 teach the language. Chapter 14 covers template fences, Chapter 15 async code, and Chapter 20 the safety guarantees. Chapters 16 to 18 open with what the browser runtime does today, then describe the Reference's fuller design; Chapter 19 is a design preview.
Listings follow these conventions:
- A plain
louplisting compiles and runs; its output follows in atextblock. - A listing labelled as not compiling is followed by the compiler's real message, then by the fix.
- A listing labelled as throwing is followed by the real
Uncaught …output. - A listing labelled as a design sketch (in the ⚠ Planned chapters) shows the specified design and is not checked by the toolchain.
- A listing labelled as running in the browser was run in Chrome on
loup-rt.wasm; its result is described after it.
Every other listing that is not a design sketch was run with Loup 1.25.1.
Table of contents
- Getting Started: installing Loup, running a
.lpwebfile, a project withloup-bootstrap init, building Wasm, running Loup in a web page, and the planned browser pipeline. - The Web Modes:
web.compiledandweb.scripted, entry points, what each mode allows, the standard library from web code. - Variables and Data Types:
let,var,const, the primitive types, numeric conversions, strings. - Functions: declarations, default and named arguments, lambdas, closures, function types, generators.
- Control Flow:
if,while,for,match,with,try/finally, and thedefergap. - Collections:
list,dict,set, tuples, and how collections are copied. - Structs: value types, construction,
withcopies, methods. - Enums and Pattern Matching:
payloads,
Option,Result, exhaustivematch. - Classes and Objects: constructors,
inheritance, visibility,
modifierandsafe, ownership verbs. - Interfaces: declaring and implementing interfaces, default methods, standard interfaces.
- Generics: type parameters, bounds, generic types.
- Error Handling: exceptions,
Result,?,attempt. - Modules and Packages: imports between
.lpwebfiles, the.lppkgmanifest, cross-mode import rules. - Template Fences — HTML and CSS: fence syntax, interpolation, directives, filters, and the planned context-aware escaping.
- Async and Concurrency:
async,await,await group, and what runs eagerly today. - Reactive UI:
ui.websignals andmounttoday; the planneduimodule, components,Viewanduifences. - Web Components: custom elements with
web.componentstoday; the planned@webcomponentclasses. - DOM, Storage, Workers, and JavaScript Interop:
web.dom,web.storageandweb.jstoday; the plannedextern js,@jsexport,lang.interop.jsand workers. - ⚠ SSR, Hydration, and Deployment:
what
--target browserproduces today, and the planned SSR, hydration and deployment design. - Memory Safety in Web Apps: what Loup checks for you today, and what the planned browser defences add.
The Language Reference
The normative description of every feature is the Loup Language Reference:
the core, runtime, compilation and data volumes
(specs/loup-language-core-v1_20.md
and its siblings). This book cites it as "Language Reference §V-N.M", where V
is the volume (1 core, 2 runtime, 3 compilation, 4 data); for example, §1-2.6
is the feature matrix of the six modes in the core volume. Where this book
and the Reference disagree, the Reference describes the intended design and
the toolchain decides what works today; this book says which is which.