Install Onyx
Run the following command on your Linux or MacOS system to install the latest version of Onyx.
Read the Installation Guide for more details.
Language Features
For full language documentation and reference see the Onyx Book.
Modern 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)
}
Type Safety
Onyx is strictly type-checked. The type-inference in Onyx allows for many types to be omitted with out sacrificing safety.
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("Value: {}.\n", change_value(x))
}
Fast Compilation
Onyx's compiler is written entirely in C and features a incredibly fast compilation. The server for this site was compiled in just 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
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.
# 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!
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.
Recent News
Beta Release 0.1.13
8th November 2024
Its been nearly 6 months since a release of Onyx — which is way too long! I've been putting off releasing this version until I felt there were enough changes to justify a new release. Now there are so many little changes made over these past months, it is due time to push them out to everyone!
Beta Release 0.1.12
19th May 2024
This intermediate release brings quality of life improvements to the pipe operator, small syntax refinements, and small improvements to WebAssembly module generation.