Module debris_llir::function_interface
source · Expand description
This module contains a trait ToFunctionInterface
which allows to write nice function interfaces
by using much less boilerplate to define functions.
Examples:
ⓘ
use debris_core::{objects::{ObjInt, FunctionContext}, ObjectRef, error::LangResult};
/// The most general form of a function
fn foo(ctx: &mut FunctionContext, objects: &[ObjectRef]) -> LangResult<ObjectRef> {
// [...]
}
/// Return types can be anything that can be converted into a LangResult<ObjectRef>, so this is also valid
fn bar(ctx: &mut FunctionContext, objects: &[ObjectRef]) -> ObjectRef {
// [...]
}
/// Instead of taking an arbitrary amount of any object, it is possible to specify which objects are required
fn square(_ctx: &mut FunctionContext, value: &ObjInt) -> ObjInt {
// [...]
}
/// Since integers can be converted into `ObjStaticInt`, this is also possible
/// Note that `ctx` can be omitted if it is not needed
fn square_static(value: &ObjStaticInt) -> i32 {
value.value * value.value
}
Macros
- count 🔒
- This macro works much like
impl_to_function_interface
by implementing the array downcast trait for tuples of variable lengths - Maps a valid return type from
$from
to$to
- Implements the
ToFunctionInterface
trait for functions with a variable amount of parameters
Structs
- The common type for working with callbacks
Traits
- This trait allows downcasting an entire array of objects into a tuple of concrete payloads
- This trait can convert functions into compatible interface functions
- Trait used for converting any valid return value into a
Option<LangResult<ObjectRef>>