Skip to main content

Module native

Module native 

Source
Expand description

§Native Function Interop

This module provides traits and macros for calling Rust functions from Lisp code.

§Overview

The native function interop system allows you to:

  • Register Rust functions that can be called from Lisp
  • Automatically convert Lisp values to Rust types and back
  • Handle errors gracefully

§Key Traits

  • FromLisp - Convert a Lisp value to a Rust type
  • ToLisp - Convert a Rust type to a Lisp value

§Usage

use grift_eval::{NativeRegistry, register_native};

// Define a native function using the register_native! macro
register_native!(add_one, (x: isize) -> isize, { x + 1 });

// Register it with an evaluator
// eval.register_native("add-one", add_one).unwrap();

§Design Notes

This module is no_std compatible and uses no heap allocation. All conversions work directly with arena-allocated values.

Structs§

NativeEntry
A registered native function with its name.
NativeRegistry
Registry for native functions.

Constants§

MAX_NATIVE_FUNCTIONS
Maximum number of native functions that can be registered.

Traits§

FromLisp
Trait for converting Lisp values to Rust types.
ToLisp
Trait for converting Rust types to Lisp values.

Functions§

args_empty
Check if the argument list is empty (nil).
count_args
Count the number of arguments in a list.
extract_arg
Extract a single argument from a Lisp argument list.
simple_hash
Simple hash function for native function names.

Type Aliases§

NativeFn
A native function that can be called from Lisp.