Skip to main content

Isle

Struct Isle 

Source
pub struct Isle { /* private fields */ }
Expand description

Handle to a thread-isolated Lua VM.

Isle owns the communication channel and the join handle for the Lua thread. All operations are thread-safe (Isle: Send + Sync).

§Lifecycle

  1. Isle::spawn creates the Lua VM on a dedicated thread.
  2. Use eval, call, or exec to run code.
  3. shutdown sends a graceful stop signal and joins the thread.

If the Isle is dropped without calling shutdown, the channel disconnects and the Lua thread exits on its next receive attempt.

Implementations§

Source§

impl Isle

Source

pub fn spawn<F>(init: F) -> Result<Self, IsleError>
where F: FnOnce(&Lua) -> Result<(), Error> + Send + 'static,

Spawn a new Lua VM on a dedicated thread.

The init closure runs on the Lua thread before any requests are processed. Use it to register globals, install mlua-pkg resolvers, load mlua-batteries, etc.

§Errors

Returns IsleError::Init if the init closure fails.

Source

pub fn eval(&self, code: &str) -> Result<String, IsleError>

Evaluate a Lua chunk (blocking).

Returns the result as a string. Equivalent to spawn_eval(code).wait().

Source

pub fn spawn_eval(&self, code: &str) -> Task

Evaluate a Lua chunk, returning a cancellable Task.

Source

pub fn call(&self, func: &str, args: &[&str]) -> Result<String, IsleError>

Call a named global Lua function with string arguments (blocking).

Source

pub fn spawn_call(&self, func: &str, args: &[&str]) -> Task

Call a named global Lua function, returning a cancellable Task.

Source

pub fn exec<F>(&self, f: F) -> Result<String, IsleError>
where F: FnOnce(&Lua) -> Result<String, IsleError> + Send + 'static,

Execute an arbitrary closure on the Lua thread (blocking).

The closure receives &Lua and can perform any operation. This is the escape hatch for complex interactions that don’t fit into eval or call.

Note: The cancel hook only fires during Lua instruction execution. If the closure blocks in Rust code (e.g. HTTP calls, file I/O), cancellation will not take effect until control returns to the Lua VM.

Source

pub fn spawn_exec<F>(&self, f: F) -> Task
where F: FnOnce(&Lua) -> Result<String, IsleError> + Send + 'static,

Execute a closure on the Lua thread, returning a cancellable Task.

Source

pub fn shutdown(self) -> Result<(), IsleError>

Graceful shutdown: signal the Lua thread to exit and join it.

After shutdown, all subsequent requests will return IsleError::Shutdown.

Source

pub fn is_alive(&self) -> bool

Check if the Lua thread is still alive.

Trait Implementations§

Source§

impl Drop for Isle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Isle

§

impl RefUnwindSafe for Isle

§

impl Send for Isle

§

impl Sync for Isle

§

impl Unpin for Isle

§

impl UnsafeUnpin for Isle

§

impl UnwindSafe for Isle

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> MaybeSend for T