README

On this page

Basic BoxLang Project

This example shows a minimal multi-file BoxLang project with a script entry point and model classes split across separate files — the most common project structure for a BoxLang application.

Project Layout

basic_project/
├── main.bxs            ← entry point (run this)
└── models/
    ├── ISpeakable.bxs  ← interface definition
    ├── Animal.bxs      ← base class
    └── Dog.bxs         ← subclass (extends Animal, implements ISpeakable)

Running

Run the project directly with the MatchBox interpreter from this directory:

matchbox main.bxs

Expected output:

=== MatchBox Basic Project ===

--- Descriptions ---
I am Whiskers and I make the sound 'Meow'
I am Rex and I make the sound 'Woof'

--- Speak ---
Meow!
Rex barks: Woof! Woof!

--- Dog Only ---
Rex fetches the ball!
Rex fetches the frisbee!

--- Roster ---
  Whiskers — Cat
  Rex — Dog

All done!

Compile to Bytecode

Compile to a portable .bxb bytecode file for faster repeated execution:

matchbox --build main.bxs
matchbox main.bxb

Compile to a Native Binary

Produce a single self-contained executable (~500 KB, no runtime required):

matchbox --target native main.bxs
./main

Key Concepts

ConceptWhere to look
Class definitionmodels/Animal.bxs
Inheritancemodels/Dog.bxs (extends Animal)
Interfacemodels/ISpeakable.bxs
Multi-file importsmain.bxs (import models.Animal)
Struct literalsmain.bxs (roster array)
For-in loopmain.bxs (roster iteration)

How Multi-File Imports Work

MatchBox resolves imports using dot-separated paths relative to the directory where matchbox is invoked. import models.Animal maps to models/Animal.bxs relative to the current working directory.

Always run matchbox main.bxs from the basic_project/ directory so that the models.* imports resolve correctly.

Edit this page Download Markdown Last updated Sep 30, 2026, 8:17:14 PM