Skip to main content

Crate intuicio_derive

Crate intuicio_derive 

Source
Expand description

Procedural macros that expose Rust items to the Intuicio runtime.

Every Intuicio function, native or scripted, has the same shape: fn(&mut Context, &Registry). It pops its arguments off the context stack and pushes its results back. Writing that shim by hand for each native function is noisy and easy to get wrong, so these macros generate it from the ordinary Rust signature, along with the description the registry needs.

MacroApplied toProduces
intuicio_functiona free fna module named after the fn, holding define_function
intuicio_methodsan inherent impl<method>__define_function for each marked method
intuicio_methoda method inside such an implnothing, it only marks the method
IntuicioStructa structan IntuicioStruct::define_struct impl
IntuicioEnuma #[repr(u8)] enuman IntuicioEnum::define_enum impl

Nothing registers itself. Each macro only writes a define_* function that you call, so registration stays explicit and ordered:

#[intuicio_function(module_name = "lib")]
fn add(a: i32, b: i32) -> i32 {
    a + b
}

registry.add_function(add::define_function(&registry));

Every define_* function looks the types in its signature up in the registry by name and panics when one is missing, so types have to be registered before the functions that mention them.

Rust visibility carries over: pub stays public, pub(crate) and pub(in ...) become Visibility::Module, and a private item becomes Visibility::Private.

§Transformers

transformer = "SomeTransformer" routes every argument and result through a ValueTransformer. The transformer decides which box travels on the stack in place of T, &T and &mut T, for example a managed value instead of a bare one. dependency = "arg" names the argument that a returned reference borrows from, so the transformer can tie the result to an owner that is still alive.

§Attribute syntax

Values are always string literals, even for names: name = "add", not name = add. Flags such as debug stand alone.

Registered names are kept as strings and never have to be Rust identifiers, so name = "+" or module_name = "core/ops" are fine. Only the names the script side sees are affected. The Rust items keep their own names.

Attribute Macros§

intuicio_function
Wraps a free function so scripts can call it.
intuicio_method
Marks a method inside an intuicio_methods block for exposure.
intuicio_methods
Wraps the methods of an inherent impl so scripts can call them.

Derive Macros§

IntuicioEnum
Describes a #[repr(u8)] enum to the registry as a native type.
IntuicioStruct
Describes a struct to the registry as a native type.