Guide
Modules and packages
Modules and Import, visibility, project.toml, local dependencies, libraries, and native libraries.
One .fb file is one module. Everything it declares is private unless it’s Public, seen by
every module that imports it, or Package, seen by its package’s other files. Circular imports
are allowed.
Imports
Import std.math // a module of std's, or a folder of them
Import std.collections As C // only as C.Stack, C.Map
From std.text.regex Import Regex // only RegexA quoted path, like Import "./ui/hud", imports a file of the package by where it is from this one: ui/hud.fb beside it.
Import X brings X’s Public names in unqualified, and under X’s last name too, as hud.Draw.
Every std name needs its Import, std.core’s too. An Import line comes first in its file.
Packages
A package is a folder with a project.toml. Its modules are named by the package’s name and
their paths, so ui/hud.fb in the package game is game.ui.hud. Its main file, main.fb
unless main says otherwise, holds the program’s top-level code.
[project]
name = "shop"
version = "0.1.0"Import std.core
Public Const TAX_PERCENT = 8
Public Function WithTax(cents: Int): Int => cents + cents * TAX_PERCENT / 100
Package Function Round(cents: Int): Int => (cents + 50) / 100 * 100Import std.core
Import shop.prices
Local price = 1999
Print("{price} with {TAX_PERCENT}% tax is {WithTax(price)}, about {Round(WithTax(price))}")1999 with 8% tax is 2158, about 2200
fb build in the folder writes build/shop, or build/shop.exe on Windows; fb run builds
and runs it.
Dependencies
Until the package registry, a dependency is another package’s folder, by its path from the
project.toml:
[dependencies]
physics = { path = "../physics" }Only a package that depends on physics can Import physics, which brings in the modules in its
folder but its main file, and Import physics.shapes its shapes.fb or shapes/ folder.
Libraries
A package without a main file is a library, type = "library". It’s built into each program
that uses it, or beside the program as a library file of its own, as the program’s
project.toml says; and a library can be built ahead of time, with an interface file of its
Public API, so it ships without its source. The spec’s chapter on modules
has how.
Native libraries
[native] names a package’s C libraries, which its Extern blocks name with Lib. Static ones
link into the executable, so a game is still one file:
[native]
joltc = { static = "libs/joltc" } # libs/libjoltc.a or libs/joltc.lib
m = { system = "m" } # one the system's linker finds
engine = { dynamic = "native/{target}/engine" }The project.toml reference lists every key, and C libraries how to call one.
Report an issue with this page or with FutureBlitz on GitHub.