The Onyx Programming Language

A type-safe, expressive, and data-oriented programming language

$ # Install Onyx in one command
$ sh <(curl https://get.onyxlang.io -sSfL) Copy
$ # Read the docs
$ # Try Onyx in your browser

Language Features

For full language documentation and reference see the Onyx Book.

Syntax


Onyx uses a modernized C-like syntax, similar to Jai or Odin. Onyx is a procedural language, but does allow for functional-inspired syntax using the pipe operator.

use core { printf, iter }

main :: () {
    for i in 1 .. 10 {
        fact := factorial(i);
        printf("{}! = {}\n", i, fact);
    }
}

factorial :: (n: i32) -> i32 {
    return iter.as_iter(1 .. n)
        |> iter.fold(1, (x, y) => x * y);
}
use core { printf }

main :: () {
    // Inferred variable type
    x := 10;

    // Function with entirely inferred types.
    change_value :: x => x + 10;

    // Onyx figures out the types of
    // `change_value` when you call it.
    printf("The value is {}.\n", change_value(x));
}

Type Safety


Onyx is strictly type-checked. However, the type-inference systems in Onyx usually allow you to omit types.

Fast Compilation


Onyx's compiler is written entirely in C and features incredibly fast compilation. The web-server for this website was compiled in 47 milliseconds.

$ onyx build -V build.onyx

File search path:
	/home/brendan/.onyx
	.

Type table size: 151092 bytes.
Foreign blocks size: 8 bytes.
Tagged procedure size: 840 bytes.
Tagged global size: 8 bytes.

Statistics:
    Time taken: 47.000000 ms
    Processed 22144 lines
    Processed 115240 tokens 

Outputting to WASM file:   site.wasm
# Compile and run directly.
$ onyx run hello.onyx
Hello, World!

# This time target 'WASI'.
$ onyx build -r wasi -o hello.wasm hello.onyx

# Run using Wasmer.
$ wasmer run hello.wasm
Hello, World!

WebAssembly


Onyx compiles solely to WebAssembly. You can use a builtin WebAssembly runtime using onyx run, or compile to WASM and run using a WebAssembly runner, like Wasmer or Wasmtime.

C-FFI


Onyx features built-in support for linking to native C-libraries on Linux and MacOS.

use core {*}

// Using #dyncall dynamically loads
// the library at runtime using dlopen().
#foreign #dyncall "libc.so" {
    write :: (fd: i32, msg: [] u8) -> i32 ---
}

main :: () {
    msg: [] u8 = "Hello, libc!";

    write(1, msg);
}

Examples

Learn more from complete examples on the Examples page.

Onyx Community

The Onyx programming language is on Discord! It is the place to chat about language features, discuss problems you are having, and showcase your projects.

Onyx is an open source project so contributions from the community are welcome and encouraged! The onyx-lang/onyx GitHub repository is the official source of Onyx.

Join Discord Go to GitHub

Recent News

Beta Release 0.1.10

31st March 2024


This release brings standard library uniformity, minor syntax changes, and JavaScript interop! You can now easily interface with the DOM and other JS APIs from directly within Onyx.

Beta Release 0.1.9

19th February 2024


This release brings major syntax changes, optional semicolons, OVM-WASM support for MacOS, and a host of bugfixes in the compiler and the standard library.

© 2020-2024 Brendan Hansen