oxeon 0.0.6

Rust-like scripting language for modding Bevy games, compiled to sandboxed WebAssembly.
Documentation
# Oxeon

A Rust-like scripting language for modding [Bevy](https://bevyengine.org) games.

**Try it in your browser: [oxeon.dev/play](https://oxeon.dev/play/).** Write mods for a small Bevy game and play it; the compiler, the sandbox and the game all run on the page.

Mods are written in a subset of Rust, compiled to WebAssembly and run sandboxed in [Wasmtime](https://wasmtime.dev). They use Bevy's own ECS and reflection, so a mod's systems and components look like ordinary Bevy code:

```rust
// mods/regen.ox
fn regen(time: Res<Time>, mut q: Query<(&mut Health, &Regen)>) {
    for (mut hp, regen) in &mut q {
        hp.0 += regen.per_sec * time.delta_secs();
    }
}

pub fn plugin(app: &mut App) {
    app.add_systems(Update, regen);
}
```

```rust
// In the game
#[derive(Component, Reflect)]
#[reflect(Component)]
struct Health(f32);

App::new()
    .add_plugins(DefaultPlugins)
    .add_plugins(oxeon::OxeonPlugin::default())
    .expose_to_mods::<Health>() // mods see the game's real types
    .expose_to_mods::<Regen>()
    .run();
```

> **Status:** early development. Mods run in Bevy: systems that take `Res`/`ResMut` of the game's resources, `Commands`, `MessageReader`/`MessageWriter`, and `Query`s over the game's components and their own (with `Entity`, `With`, `Without`, `Changed` and `Added`) run in `Startup` and `Update`, with fuel limits and hot reloading. The compiler handles numbers, structs, enums and tuples by value, `match` and patterns, control flow and methods; generics, closures, traits (static dispatch and `&dyn Trait`), `Option` and `Result` with `?` and their methods, `Vec<T>` and `vec!`, `Box<T>` and `Box<dyn Trait>`, Rust's methods on numbers (`count_ones`, `sqrt`, `round`, ...), all checked by a borrow checker like Rust's. See [docs/ROADMAP.md](docs/ROADMAP.md).

## Features (planned)

- Rust semantics: ownership, borrowing, lifetimes, traits, generics, enums, pattern matching, closures, `Result` and `?`
- A sandbox that is safe for untrusted mods: fuel limits, per-mod capabilities, and a trapped mod never crashes the game
- Hot reloading, with mod state carried across reloads through reflection
- Bindings generated from the game's Bevy `TypeRegistry`
- `async`/`.await` driven by the host's executor
- Procedural macros that run sandboxed, and compile-time evaluation

The decisions behind these are in [docs/DESIGN.md](docs/DESIGN.md).

## Workspace

| Crate | Purpose |
|---|---|
| [`oxeon`](crates/oxeon) | The Bevy plugin, which is the crate games depend on |
| [`oxeon-shim`](crates/oxeon-shim) | The mod API implemented natively in Rust |
| [`oxeon-cli`](crates/oxeon-cli) | The `oxeon` command-line tool |
| [`oxeon-lsp`](crates/oxeon-lsp) | Language server |
| [`editors/vscode`](editors/vscode) | VS Code extension |
| [`oxeon-compiler`](crates/oxeon-compiler) | Compiler pipeline driver |
| [`oxeon-syntax`](crates/oxeon-syntax), [`oxeon-types`](crates/oxeon-types), [`oxeon-mir`](crates/oxeon-mir), [`oxeon-codegen`](crates/oxeon-codegen) | Compiler stages |
| [`oxeon-runtime`](crates/oxeon-runtime) | Sandboxed runtime: Wasmtime natively, the browser's engine on the web |
| [`oxeon-diagnostics`](crates/oxeon-diagnostics) | Spans and error reporting |

```sh
cargo test --workspace
cargo run -p oxeon --example regen        # a headless game running a mod
cargo run -p oxeon-cli -- parse examples/mods/regen.ox
```

## License

Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.