Skip to content

Packages

A Lisette project is made up of packages. A package is a directory, and its name is the namespace for all .lis files inside. In the example below, user.lis and post.lis belong to the models package.

  • Directorymy-app/
    • lisette.toml project manifest
    • Directorysrc/
      • main.lis entry point
      • Directorymodels/ models package
        • user.lis
        • post.lis
      • Directoryroutes/ routes package
        • api.lis
        • Directoryadmin/ routes/admin package
          • panel.lis

To import a package from your project:

import "models"package path, relative to project root
import "routes/admin"nested package path

Imported packages are namespaces:

import "models"
fn main() {
let user = models.User { name: "Alice" }
models.save(user)
}

To alias an imported package:

import m "models"
fn main() {
let user = m.User { name: "Alice" }
m.save(user)
}

Circular imports are disallowed.

Definitions are visible to all other files in the same package. Use pub to expose them to other packages.

public
pub fn save(user: User) -> Result<(), error> {
if !validate(user) {
return Err(errors.New("email is required"))
}
Ok(())
}
private
fn validate(user: User) -> bool {
!user.email.is_empty()
}
models/user.lis

A struct and its fields can be marked pub independently, and so can a method in an impl block:

pub struct User {
pub name: string,public
email: string,private
}
impl User {
public
pub fn greet(self) -> string {
"hi " + self.name
}
private
fn label(self) -> string {
f"{self.name} <{self.email}>"
}
}
models/user.lis

Reaching a private field or method from another package is an error:

import "models"
fn handle(user: models.User) {
let name = user.nameok, public field
let greeting = user.greet()ok, public method
let email = user.emailerror, private to models
let label = user.label()error, private to models
}
main.lis

A binary project produces an executable. A project is a binary if it contains a main.lis. In a binary project, lis build compiles all .lis files under src/ and writes the executable to target/.lisette/bin/.

  • Directoryapp/
    • lisette.toml
    • Directorysrc/
      • main.lis entry point present
      • Directorymodels/
        • user.lis
    • Directorytarget/
      • Directory.lisette/
        • Directorybin/
          • app executable

A library project produces Go source code for Go users to import. A project is a library if it contains no main.lis. lis build mirrors src/ into target/, where each dir becomes a Go package and the files at the top become the lib’s root package.

  • Directorygeo/
    • lisette.toml
    • Directorysrc/ entry point absent
      • geo.lis
      • Directoryshapes/
        • shapes.lis
    • Directorytarget/
      • go.mod
      • geo.go package geo
      • Directoryshapes/
        • shapes.go package shapes

Set name in lisette.toml to the Go module path Go users will import.

[project]
name = "github.com/you/geo"
version = "0.1.0"
lisette.toml

A Go user then imports it like any other module:

import (
"fmt"
"github.com/you/geo"
"github.com/you/geo/shapes"
)
func main() {
fmt.Println(geo.Area(), shapes.Perimeter())
}
main.go