Skip to main content

Examples

Every example on these pages is a real program that compiles and runs. The sources live in the examples/ directory of the Nebra repository, so you can clone it and run each one yourself:

git clone https://github.com/nebra-lang/nebra.git
cd nebra/examples/zoo-app
nebra install
nebra run

What each example covers

ExampleWhat you learn
Hello, typed worldThe smallest useful program: annotations, doc comments, and what the compiler strips
Classes and interfacesModelling behaviour with interface, class, implements and arrays of a shared type
Modules and packagesLocal imports, folder modules, sub-modules and file dependencies across three packages
Typing existing LuaWrapping a plain .lua library in a .d.neb so callers get types without a rewrite
Compile-time annotationsWriting an annotation that rewrites the IR before codegen

Reading order

If you are new to Nebra, take them in the order above. Each one builds on the previous, and the last two are the ones that have no equivalent in plain Lua.

If you already know what you are looking for, the language reference is organised by feature rather than by narrative.

The repository examples

The pages here are written to be read on their own, but they are drawn from four projects that are also useful to browse directly:

examples/nebra-strings is a small library written entirely in Nebra. It exports string helpers from init.neb and has a sub-module in case.neb, so it demonstrates how a package exposes both a root entry point and addressable sub-modules.

examples/lua-math is the opposite: a library written in plain Lua with a hand-written init.d.neb that describes its types. Nothing about it was rewritten for Nebra.

examples/zoo-app consumes both of the above through the package manager, plus local sibling files and a folder module of its own. It is the end-to-end test of the import system.

examples/annotation-demo defines a @log annotation and applies it to three functions, showing the compile-time metaprogramming pipeline from definition to generated output.