pub struct Env { /* private fields */ }
Expand description
Main point of interaction with the Lisp runtime.
Implementations§
source§impl Env
impl Env
Public APIs.
pub fn intern(&self, name: &str) -> Result<Value<'_>>
pub fn type_of<'e>(&'e self, value: Value<'e>) -> Result<Value<'_>>
pub fn is_not_nil<'e>(&'e self, value: Value<'e>) -> bool
value.is_not_nil()
insteadpub fn eq<'e>(&'e self, a: Value<'e>, b: Value<'e>) -> bool
value1.eq(value2)
insteadpub fn cons<'e, A, B>(&'e self, car: A, cdr: B) -> Result<Value<'_>>
pub fn list<'e, A>(&'e self, args: A) -> Result<Value<'_>>where
A: IntoLispArgs<'e>,
pub fn provide(&self, name: &str) -> Result<Value<'_>>
pub fn message<T: AsRef<str>>(&self, text: T) -> Result<Value<'_>>
source§impl Env
impl Env
sourcepub unsafe fn make_user_ptr(
&self,
fin: emacs_finalizer_function,
ptr: *mut c_void
) -> Result<Value<'_>>
pub unsafe fn make_user_ptr( &self, fin: emacs_finalizer_function, ptr: *mut c_void ) -> Result<Value<'_>>
Creates and returns a user-ptr
object that wraps the raw pointer ptr
. When the object is
garbage-collected, fin
will be called with ptr
as the only argument. If fin
is None,
no finalization will be done.
In general, prefer the user-ptr
supported provided by the defun
attr macro. Use this
function only for special user-ptr
types, such as newtypes wrapping opaque pointers.
§Safety
The pointer must be valid until the finalizer is called. The finalizer itself must finalize the pointer in a safe manner.
source§impl Env
impl Env
sourcepub fn define_error<'e, N, P>(
&'e self,
name: N,
message: &str,
parents: P
) -> Result<Value<'e>>where
N: IntoLispSymbol<'e>,
P: IntoLispArgs<'e>,
pub fn define_error<'e, N, P>(
&'e self,
name: N,
message: &str,
parents: P
) -> Result<Value<'e>>where
N: IntoLispSymbol<'e>,
P: IntoLispArgs<'e>,
Defines a new Lisp error signal. This is the equivalent of the Lisp function’s define-error
.
The error name can be either a string, a Value
, or a GlobalRef
.
source§impl Env
impl Env
sourcepub fn call<'e, F, A>(&'e self, func: F, args: A) -> Result<Value<'_>>where
F: IntoLispCallable<'e>,
A: IntoLispArgs<'e>,
pub fn call<'e, F, A>(&'e self, func: F, args: A) -> Result<Value<'_>>where
F: IntoLispCallable<'e>,
A: IntoLispArgs<'e>,
Calls a Lisp function, passing the given arguments.
func
should be a string, or a Lisp’s callableValue
(in which casefunc.call
is preferable). An error is signaled otherwise.args
should be an array/slice ofValue
, or a tuple of different types, each implementingIntoLisp
.
§Examples
#[defun]
fn listify_vec(vector: Vector) -> Result<Value> {
let env = vector.value().env;
let mut args = vec![];
for elem in vector {
args.push(elem)
}
env.call("list", &args)
}