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.
| Macro | Applied to | Produces |
|---|---|---|
intuicio_function | a free fn | a module named after the fn, holding define_function |
intuicio_methods | an inherent impl | <method>__define_function for each marked method |
intuicio_method | a method inside such an impl | nothing, it only marks the method |
IntuicioStruct | a struct | an IntuicioStruct::define_struct impl |
IntuicioEnum | a #[repr(u8)] enum | an 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(®istry));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_methodsblock for exposure. - intuicio_
methods - Wraps the methods of an inherent
implso scripts can call them.
Derive Macros§
- Intuicio
Enum - Describes a
#[repr(u8)]enumto the registry as a native type. - Intuicio
Struct - Describes a
structto the registry as a native type.