Modules & projects
Organize code with import, module, and main.ny projects.
Project layout
After nyrapkg init, only main.ny, nyra.mod, nyra.lock, and nyra.sum exist. Full file roles: NyraPkg → project files.
Importing source files
Paths are relative to the file that contains the import:
import "src/helpers.ny"
import "lib/api.ny"
import { add, mul } from "src/math.ny"
import { greet as hi } from "src/helpers.ny"import "src/helpers.ny"
import "lib/api.ny"
import { add, mul } from "src/math.ny"
import { greet as hi } from "src/helpers.ny"
Whole-module import "path" merges all pub items.
Selective import { a, b } from "path" merges only those names (plus same-file helpers they need) — prefer for lean builds.
Use pub / priv on functions, structs, enums, and const (default: public).
Details: Imports guide → selective.
Import alias & qualified names
Rename a whole-module import and call through :: (desugars to alias__symbol):
import "src/helpers.ny" as h
fn main() {
print(h::greet("nyra"))
}import "src/helpers.ny" as h
fn main() -> void {
print(h::greet("nyra"))
}Without as, public symbols keep their original names. priv items stay in the defining file only.
For renaming a single symbol without a module prefix, use selective import: import { greet as hi } from "…".
Running a project
| Command | Use when |
|---|---|
nyra run or nyra run . | Project has main.ny + optional imports |
nyra build or nyra build . | Emit target/debug/main |
nyra build --release | Emit optimized target/release/main |
nyra run main.ny | Single self-contained file only |
Build artifacts
myapp/
main.ny
target/
debug/main
release/main
Run the shipped binary directly: ./target/release/main (or main.exe on Windows). Add target/ to .gitignore.
Module declaration
module github.com.you.myapp
Optional first line; pairs with nyra.mod for NyraPkg.
nyra.mod
Line-oriented project manifest (like a tiny Cargo.toml). Minimum is just module …. Full directive table: nyra.mod syntax reference.
module example.local
version 1.0.0
tls rustls # optional — HTTPS backend (default rustls)
require ny-sqlite ^0.1.0
require https://github.com/example/ny-lib
link sqlite3
Edit require lines by hand or via nyrapkg add. Then nyra run . auto-syncs (fetch missing packages, prune removed ones) — or run nyrapkg sync. Details: NyraPkg → manual require. TLS backends: net/http → TLS.
Quick pattern: split UI and logic
logic.nyfn compute() -> i32 { return 100 }
main.ny
import "logic.ny"
fn main() { print(compute()) }main.ny
import "logic.ny"
fn main() -> void { print(compute()) }