The Loup Web Book — contents
  1. Chapter 1: Getting Started
  2. Chapter 2: The Web Modes
  3. Chapter 3: Variables and Data Types
  4. Chapter 4: Functions
  5. Chapter 5: Control Flow
  6. Chapter 6: Collections
  7. Chapter 7: Structs
  8. Chapter 8: Enums and Pattern Matching
  9. Chapter 9: Classes and Objects
  10. Chapter 10: Interfaces
  11. Chapter 11: Generics
  12. Chapter 12: Error Handling
  13. Chapter 13: Modules and Packages
  14. Chapter 14: Template Fences — HTML and CSS
  15. Chapter 15: Async and Concurrency
  16. Chapter 16: Reactive UI
  17. Chapter 17: Web Components
  18. Chapter 18: DOM, Storage, Workers, and JavaScript Interop
  19. Chapter 19: SSR, Hydration, and Deployment
  20. Chapter 20: Memory Safety in Web Apps

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 the web.dom, web.storage, web.js, web.components and ui.web modules. 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.js for web.compiled builds, the HTML shell, loup serve, the ui module 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:

  • int arithmetic wraps on overflow instead of throwing (the sized types such as int32 do throw).
  • [1, 2] == [1, 2] is false: collection equality is not element-wise yet.
  • A defer body never runs; use try/finally for cleanup.
  • async functions run eagerly at the call; a failure surfaces at the call, not at await.
  • html fences do not escape interpolated values; use the escape filter.
  • panic is undefined in web code; throw an exception instead.
  • A web.compiled file cannot import any standard-library module (E_COMPILED_IMPORT_SCRIPTED); web.scripted files can.
  • In Wasm builds, i"…" interpolated strings, // and for await stop the program at run time; the same code runs under loup run and in the browser runtime.
  • The browser runtime does not report type errors: a program the type checker rejects prints nothing and eval returns 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.compiled is the browser's ahead-of-time mode. A file holds only declarations. The runner calls main(), so that is where the program starts (Chapter 2).
  • web.scripted is 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 loup listing compiles and runs; its output follows in a text block.
  • 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

  1. Getting Started: installing Loup, running a .lpweb file, a project with loup-bootstrap init, building Wasm, running Loup in a web page, and the planned browser pipeline.
  2. The Web Modes: web.compiled and web.scripted, entry points, what each mode allows, the standard library from web code.
  3. Variables and Data Types: let, var, const, the primitive types, numeric conversions, strings.
  4. Functions: declarations, default and named arguments, lambdas, closures, function types, generators.
  5. Control Flow: if, while, for, match, with, try/finally, and the defer gap.
  6. Collections: list, dict, set, tuples, and how collections are copied.
  7. Structs: value types, construction, with copies, methods.
  8. Enums and Pattern Matching: payloads, Option, Result, exhaustive match.
  9. Classes and Objects: constructors, inheritance, visibility, modifier and safe, ownership verbs.
  10. Interfaces: declaring and implementing interfaces, default methods, standard interfaces.
  11. Generics: type parameters, bounds, generic types.
  12. Error Handling: exceptions, Result, ?, attempt.
  13. Modules and Packages: imports between .lpweb files, the .lppkg manifest, cross-mode import rules.
  14. Template Fences — HTML and CSS: fence syntax, interpolation, directives, filters, and the planned context-aware escaping.
  15. Async and Concurrency: async, await, await group, and what runs eagerly today.
  16. Reactive UI: ui.web signals and mount today; the planned ui module, components, View and ui fences.
  17. Web Components: custom elements with web.components today; the planned @webcomponent classes.
  18. DOM, Storage, Workers, and JavaScript Interop: web.dom, web.storage and web.js today; the planned extern js, @jsexport, lang.interop.js and workers.
  19. ⚠ SSR, Hydration, and Deployment: what --target browser produces today, and the planned SSR, hydration and deployment design.
  20. 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.

Chapters

  1. Chapter 1: Getting Started

    This chapter installs Loup, runs a first .lpweb program, sets up a project, and compiles it to WebAssembly. Then it runs Loup in a web page with the browser runtime, and ends with the fuller browser…

  2. Chapter 2: The Web Modes

    Loup has six execution modes. Two of them are for the web: web.compiled and web.scripted. This chapter covers how a file declares its mode, where each web mode starts running, what each mode allows,…

  3. Chapter 3: Variables and Data Types

    What you'll learn. How let, var and const differ, the primitive types, how integers and floats behave (including what happens on overflow today), characters and strings, bytes, Option instead of…

  4. Chapter 4: Functions

    What you'll learn. How to declare functions, default and named arguments, lambdas and closures, function types, higher-order functions, a first look at generic functions and generators, property…

  5. Chapter 5: Control Flow

    What you'll learn. if / else if / else as statements and expressions, while, do/while, the two for loops, labeled break and continue, match, the cleanup tools (try/finally, defer, with), and the…

  6. Chapter 6: Collections

    What you'll learn. The built-in collections list[T], dict[K, V] and set[T], plus tuples: their literals, the methods each one has, slicing, list comprehensions, and what happens when you assign a…

  7. Chapter 7: Structs

    What you'll learn. How to declare and construct structs, what value semantics means in practice, the with copy expression, methods and operators on structs, the pure-value invariant, and generic…

  8. Chapter 8: Enums and Pattern Matching

    What you'll learn. Plain enums, enums whose variants carry data, the built-in Option[T] and Result[T, E], the patterns match accepts (literals, bindings, wildcards, guards, tuples, nested variants,…

  9. Chapter 9: Classes and Objects

    A struct (Chapter 7) is a value: two Point(x = 3, y = 4) are the same point, and assigning one copies it. A class describes an object with identity: two shopping carts holding the same items are…

  10. Chapter 10: Interfaces

    An interface is a contract: a list of methods that any type claiming to implement it must provide. Code written against the interface works with every implementation, so you can render a list of…

  11. Chapter 11: Generics

    What you'll learn. How to write functions, structs, classes, enums, and interfaces that take type parameters; how type arguments are inferred and when you must write them; how where clauses and…

  12. Chapter 12: Error Handling

    What you'll learn. Loup's two error mechanisms, exceptions and Result[T, E]; how to throw, catch, chain, and define exceptions; what an uncaught exception prints; how to handle and propagate a Result…

  13. Chapter 13: Modules and Packages

    What you'll learn. How files become modules, the from … import (…) and import … as … forms, pub visibility across files, barrel modules with pub from, the import rule between web.compiled and…

  14. Chapter 14: Template Fences — HTML and CSS

    A template fence embeds a block of another language (HTML, CSS, SQL, plain text) in Loup source and fills it with Loup values. It is the tool a web app uses to produce markup.

  15. Chapter 15: Async and Concurrency

    What you'll learn. async functions and Task[T], await, structured concurrency with await group, async generators and for await, atomic {} blocks, and spawnBlocking — and, just as important, how Loup…

  16. Chapter 16: Reactive UI

    ⚠ Partly planned. The first section, on ui.web, runs today in the browser runtime (Chapter 1, "Running Loup in the browser"). The rest of the chapter describes the design in the Language Reference…

  17. Chapter 17: Web Components

    ⚠ Partly planned. The first section, on web.components, runs today in the browser runtime (Chapter 1, "Running Loup in the browser"). The rest of the chapter describes the design in the Language…

  18. Chapter 18: DOM, Storage, Workers, and JavaScript Interop

    ⚠ Partly planned. The first section, on web.dom, web.storage and web.js, runs today in the browser runtime (Chapter 1, "Running Loup in the browser"). The rest describes the design in the Language…

  19. Chapter 19: SSR, Hydration, and Deployment

    ⚠ Planned — not in Loup 1.25. This chapter describes the design in the Language Reference (§2-4.7 for server-side rendering, hydration and state serialization, §1-16.6.7–§1-16.6.8 for SafeHtml,…

  20. Chapter 20: Memory Safety in Web Apps

    This chapter collects, bug class by bug class, what Loup does to keep a web app correct: which mistakes the compiler refuses, which ones the runtime catches, and which defences are still planned.…