The Loup Scripting Book — contents
  1. Chapter 1: Getting Started
  2. Chapter 2: Variables and Data Types
  3. Chapter 3: Functions and Closures
  4. Chapter 4: Control Flow
  5. Chapter 5: Collections
  6. Chapter 6: Structs
  7. Chapter 7: Enums and Pattern Matching
  8. Chapter 8: Classes and Objects
  9. Chapter 9: Interfaces and Generics
  10. Chapter 10: Error Handling
  11. Chapter 11: Modules and Packages
  12. Chapter 12: Strings, Interpolation, and Template Fences
  13. Chapter 13: Concurrency
  14. Chapter 14: Reflection and Dynamic Compilation
  15. Chapter 15: Reactive UI
  16. Chapter 16: Testing
  17. Chapter 17: JavaScript Host Interop
  18. Chapter 18: Building Script Tools
  19. Chapter 19: Memory Safety and Resource Management

The Loup Scripting Book

Covers: Loup 1.25 (toolchain 1.25.1) and the Loup Language Reference, the four v1.20 volumes as amended through 1.25 (core, runtime, compilation, data). Section references such as §1-2.4 point into those volumes: the first number is the volume.

This book teaches Loup through scripts: files you run with loup run, with no build step and no project, that are fully type-checked before the first line executes. By the end you will be able to write the small tools you would otherwise write in Python, Ruby or a shell script — file processing, data conversion, command-line utilities — and know when to turn a script into a compiled program.

A Script in Thirty Seconds

@mode(host.scripted)

# Count the words in a file (or in a built-in sample) and show the top three.
let argv = args();
let text = if (argv.length() > 0) { readText(argv[0]) } else { "the cat sat on the mat and the dog sat too" };

var counts: dict[string, int] = {};
for (word in text.split(" ")) {
    let w = word.trim().toLowerCase();
    if (w.length() == 0) {
        continue;
    }
    counts[w] = (counts.get(w) ?? 0) + 1;
}

var ranked = counts.entries();
ranked.sort(func(a: (string, int), b: (string, int)) => b.1 - a.1);

for ((word, n) in ranked.slice(0, 3)) {
    println(i"{$ word $}: {$ n $}");
}

Save it as wordcount.lpscr and run it:

loup run wordcount.lpscr notes.txt

With no argument it counts its built-in sample:

the: 3
sat: 2
cat: 1

No manifest, no build step, and the compiler still checks every type: pass readText a number, or forget that counts.get returns an Option, and the script is rejected before it touches the file.

Who This Book Is For

You write scripts: automation, data wrangling, small command-line tools, glue between programs. You have programmed in some language before; you do not need to know anything about Loup, WebAssembly or systems programming.

The Modes, and Where This Book Fits

Every Loup source file declares an execution mode on its first line. There are six:

Mode Extension What it is for Book
@mode(host.scripted) .lpscr Scripts: top-level statements run in order by loup run this book
@mode(host.dual) .loup Programs with a main() that run under loup run or compile to Wasm or native code this book (Chapters 1 and 18), The Loup Native Book
@mode(host.native) .lphc Native binaries The Loup Native Book
@mode(web.scripted), @mode(web.compiled) .lpweb Browser applications (no browser runtime ships yet) The Loup Web Book
@mode(freestanding) .lpfree Kernels, bootloaders, firmware The Loup Freestanding Book

Every listing in this book starts with @mode(host.scripted) (on the website, later listings in a chapter may hide that line), and script files use the .lpscr extension. When a script becomes a program, it moves to host.dual: a .loup file whose code lives in main(). Chapter 1 shows the move and Chapter 18 does it for a complete tool.

In Loup 1.25, loup run type-checks a script and runs it on an interpreter on your operating system — Linux, macOS or Windows. The Language Reference describes a JIT that compiles scripts to WebAssembly and can run on JavaScript hosts; that is not what ships, and this book describes what does.

What Works in Scripts Today

  • Static types with inference; int, float, string, bool, char, bytes, lists, dicts, sets, tuples, Option and Result
  • Functions, closures, default and named arguments, generators
  • Structs, enums with match, classes with inheritance, interfaces, generics, operator overloading
  • Exceptions (throw, try/catch/finally), Result with ?, and attempt
  • Modules and imports; projects with an .lppkg manifest
  • Interpolated strings and template fences
  • async/await (executed eagerly and in order today; see Chapter 13)
  • The ownership verbs (reads, edits, takes, shares), modifier methods and safe blocks
  • A standard library with files, processes, paths, JSON, CSV, TOML, YAML, regular expressions, time and an HTTP server
  • loup test with debug.assert

Some chapters describe parts of the language that the 1.25 toolchain does not implement yet. They are marked:

⚠ Planned — not in Loup 1.25. …

Chapters 14 (reflection), 15 (reactive UI) and 17 (JavaScript interop) are design previews in their entirety; their listings show the intended design and are not verified. Inside the other chapters, a single unimplemented feature gets a short "⚠ Planned" note instead of a runnable listing.

Table of Contents

Part I: Getting Started

  1. Getting Started
  2. Variables and Data Types
  3. Functions and Closures
  4. Control Flow
  5. Collections

Part II: Shaping Data

  1. Structs
  2. Enums and Pattern Matching
  3. Classes and Objects
  4. Interfaces and Generics

Part III: Programs at Scale

  1. Error Handling
  2. Modules and Packages
  3. Strings, Interpolation, and Template Fences

Part IV: Dynamic and Asynchronous

  1. Concurrency
  2. Reflection and Dynamic Compilation ⚠ Planned
  3. Reactive UI ⚠ Planned

Part V: Shipping Scripts

  1. Testing
  2. JavaScript Host Interop ⚠ Planned
  3. Building Script Tools
  4. Memory Safety and Resource Management

Installing Loup and Running the Examples

Official builds come from code-craft-ai-company/loup-releases. On Linux and macOS:

curl -fsSL https://github.com/code-craft-ai-company/loup-releases/releases/latest/download/loup-install.sh | sh

On Windows, in 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) and adds it to your PATH; Chapter 1 has the details. Then save a listing as example.lpscr and run it:

loup run example.lpscr

Scripts get file-system, process and secure-random access by default; network access needs --allow-net (Chapter 1, "Permissions"). If a listing spans several files, the text says how to lay them out.

Every runnable listing in this book has been checked with the Loup 1.25.1 toolchain. Listings marked as errors show the compiler's or the runtime's real output.

Ready? Start with Chapter 1.

Chapters

  1. Chapter 1: Getting Started

    What you'll learn: how to install Loup, run your first script, read the two kinds of error Loup reports, give a script the permissions it needs, and turn a script into a program with a main()…

  2. Chapter 2: Variables and Data Types

    What you'll learn: how Loup binds names to values with let, var and const; the primitive types you use every day; how to convert between numeric types; how Option[T] replaces null; and when to use…

  3. Chapter 3: Functions and Closures

    What you'll learn: how to declare functions, give parameters default values and pass arguments by name; how to write lambdas and closures, including closures that update outer variables; and how…

  4. Chapter 4: Control Flow

    What you'll learn: branching with if (as a statement and as an expression) and a first look at match; looping with while, do/while, counted for and for-in over collections and ranges; break, continue…

  5. Chapter 5: Collections

    What you'll learn: the four built-in collection types (list, dict, set, tuple), indexing and slicing, the methods each collection has, list comprehensions, spread, membership tests, and what happens…

  6. Chapter 6: Structs

    What you'll learn: how to define a struct, construct it with named arguments, give it methods and operators, make modified copies with with, and what "value semantics" means when you assign a struct…

  7. Chapter 7: Enums and Pattern Matching

    What you'll learn: how to define enums with and without payloads, take them apart with match, use guards, wildcards and nested patterns, and use the two built-in enums you will meet in almost every…

  8. Chapter 8: Classes and Objects

    What you'll learn: how to declare classes with fields, a constructor and methods; why methods that change an object are marked modifier and called inside safe; constructors, static factories and…

  9. Chapter 9: Interfaces and Generics

    What you'll learn: how to declare an interface and implement it, give an interface default methods, use the standard interfaces that power ==, <, for and with, overload operators, and write generic…

  10. Chapter 10: Error Handling

    What you'll learn: the three ways a Loup script deals with failure — Option[T] when a value may be absent, Result[T, E] when an operation can fail in an expected way, and exceptions for failures that…

  11. Chapter 11: Modules and Packages

    What you'll learn: how one script uses code from another file, how pub decides what a file exports, the import forms Loup has (and the ones it deliberately lacks), what happens when a module is…

  12. Chapter 12: Strings, Interpolation, and Template Fences

    What you'll learn: how Loup strings work, the string literal forms, the everyday string methods, interpolated strings with filters, and template fences — multi-line templates with {% if %} and {% for…

  13. Chapter 13: Concurrency

    What you'll learn: async functions and await, structured concurrency with await group, async generators and for await, atomic {} blocks, offloading work with spawnBlocking, worker scripts with…

  14. Chapter 14: Reflection and Dynamic Compilation

    ⚠ Planned — not in Loup 1.25. This chapter describes the design in the Language Reference (§1-4.7 typeof and instanceof, §1-2.3 __module__ and Module, §1-8.8 annotations, §2-5.1 runtime.compile). The…

  15. Chapter 15: Reactive UI

    ⚠ Planned — not in Loup 1.25. This chapter describes the design in the Language Reference (§2-4 Reactive UI: §2-4.1 signals, §2-4.2 components, §2-4.3 mounting, §2-4.6 the ui fence, §2-4.8 the…

  16. Chapter 16: Testing

    What you'll learn: how to write tests as ordinary Loup functions, check results with the debug.assert helpers, run them with loup test, read a failure report, skip a test that cannot run, and lay out…

  17. Chapter 17: JavaScript Host Interop

    ⚠ Planned — not in Loup 1.25. This chapter describes the design in the Language Reference (§2-3.1 extern js, §2-3.2 @jsexport, §2-3.3 the lang.interop.js facades). The toolchain does not implement it…

  18. Chapter 18: Building Script Tools

    What you'll learn: how to turn a script into a command-line tool: making it executable, reading arguments and options, reporting errors on standard error with the right exit status, walking…

  19. Chapter 19: Memory Safety and Resource Management

    What you'll learn: how long values and objects live in a Loup script, how the ownership verbs (reads, edits, takes, shares) and modifier/safe control who may change what, what unique adds, how to…