Skip to main content

Crate mimas

Crate mimas 

Source
Expand description

mimas is a statically typed, embeddable scripting language for Rust.

This crate is the front door for host programs: it re-exports the pieces of the pipeline you need and bundles the standard library, so embedding is two lines.

let mut vm = mimas::compile_source(r#"print("hello from mimas");"#).unwrap();
vm.run().unwrap();

§Sharing Rust with a script

Tag an item with mimas and the script can see it, type-checked like anything native. Structs, enums, free functions, and impl blocks all work – note that an impl needs the attribute too, not just the type it belongs to.

use mimas::mimas;

#[mimas]
struct User(String);

#[mimas]
impl User {
    fn greet(self) -> String {
        format!("Hello, {}!", self.0)
    }
}

let mut vm = mimas::compile_source(r#"print(User("mimas").greet());"#).unwrap();
vm.run().unwrap();

Multi-file projects go through compile_files. For host state, runtime errors, and the rest of the embedding surface, see the Extension with Rust guide.

§Bevy

The bevy feature adds [bevy], a plugin for running mimas scripts in a Bevy app.

Re-exports§

pub use library;
pub use vm;

Structs§

Api
Ctx
Vm

Enums§

Literal
Ty
Every type that mimas works off of. Check the book for more details.
Val

Functions§

compile_files
Compiles the given files with mimas’s std included. Files should be passed in within a tuple first containing their name then followed by their source.
compile_source
Compiles the given source with mimas’s std included.
write_api
A host run from its cargo target dir already writes target/mimas/<binary>.json. Call this to put the manifest somewhere else, like a copy committed for modders.

Attribute Macros§

mimas
Conversion and automatic registration – no manual api.add* call.
native
Conversion only – rewrites a fn(Ctx<'gc>, ..) into the shape the VM’s IntoFn / IntoMethod machinery accepts; you register it yourself. For a free fn that should just land in the prelude, use mimas instead and skip the manual api.add.

Derive Macros§

MimasEnum
MimasStruct