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
Isle::spawncreates the Lua VM on a dedicated thread.- Use
eval,call, orexecto run code. shutdownsends 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
impl Isle
Sourcepub fn spawn<F>(init: F) -> Result<Self, IsleError>
pub fn spawn<F>(init: F) -> Result<Self, IsleError>
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.
Sourcepub fn eval(&self, code: &str) -> Result<String, IsleError>
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().
Sourcepub fn spawn_eval(&self, code: &str) -> Task
pub fn spawn_eval(&self, code: &str) -> Task
Evaluate a Lua chunk, returning a cancellable Task.
Sourcepub fn call(&self, func: &str, args: &[&str]) -> Result<String, IsleError>
pub fn call(&self, func: &str, args: &[&str]) -> Result<String, IsleError>
Call a named global Lua function with string arguments (blocking).
Sourcepub fn spawn_call(&self, func: &str, args: &[&str]) -> Task
pub fn spawn_call(&self, func: &str, args: &[&str]) -> Task
Call a named global Lua function, returning a cancellable Task.
Sourcepub fn exec<F>(&self, f: F) -> Result<String, IsleError>
pub fn exec<F>(&self, f: F) -> Result<String, IsleError>
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.
Sourcepub fn spawn_exec<F>(&self, f: F) -> Task
pub fn spawn_exec<F>(&self, f: F) -> Task
Execute a closure on the Lua thread, returning a cancellable Task.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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