Skip to content
FutureBlitz

    Install

    The tour, 11 of 11

    Modules and packages

    One file is one module, Public is what other files see, and project.toml makes a package.

    Each .fb file is a module. What it declares is private to it unless it’s marked Public, and another file uses it with Import. There’s no textual include.

    A package is a folder with a project.toml, which names it, and its main file, main.fb, whose top-level code is the program. Its other files are modules named by the package’s name and their paths: combat.fb in the package arena is arena.combat.

    project.toml
    [project]
    name = "arena"
    version = "0.1.0"
    combat.fb
    Import std.core
    
    Public Struct Fighter
        Public Field name: String
        Public Field attack: Int
    End Struct
    
    Public Function Duel(a: Fighter, b: Fighter): String
        Return a.attack >= b.attack ? a.name : b.name
    End Function
    
    Function Secret(): Int => 42            // only combat.fb sees this
    main.fb
    Import std.core
    Import arena.combat
    
    Local winner = Duel(Fighter("Ada", 7), Fighter("Grace", 9))
    Print("{winner} wins")
    Output
    Grace wins

    fb run in the folder builds the package and runs it.

    Imports

    Import std.core                     // a module of std's
    Import std.collections              // a folder: each of its files' modules
    Import std.math As M                // only as M.Vec3, M.Lerp
    From std.text.regex Import Regex    // only the names it lists
    
    Local v = M.Vec3(1, 2, 3)
    Print(v, Try Regex("a+").IsMatch("caaat"))

    A package’s dependencies go in its project.toml’s [dependencies], by their folders for now; a package registry comes later. The modules and packages guide has the rest. That’s the tour: next, the tutorial builds a game, a tool, and a web service, the docs go deeper on each part, and std’s reference has every module.

    Report an issue with this page or with FutureBlitz on GitHub.