Skip to main content

LuaRuntime

Struct LuaRuntime 

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

Manages the Lua state for extensions.

Implementations§

Source§

impl LuaRuntime

Source

pub fn new() -> Result<Self, LuaError>

Create a new Lua runtime with standard libraries.

Source

pub fn lua(&self) -> &Lua

Get a reference to the underlying Lua state.

Source

pub fn tools(&self) -> Arc<Mutex<Vec<LuaToolHandle>>>

Get a clone of the tools handle for external access.

Source

pub fn hooks(&self) -> Arc<Mutex<Vec<LuaHookHandle>>>

Get a clone of the hooks handle for external access.

Source

pub fn commands(&self) -> Arc<Mutex<Vec<LuaCommandHandle>>>

Get a clone of the commands handle for external access.

Source

pub fn native_tools(&self) -> Arc<Mutex<HashMap<String, Arc<dyn Tool>>>>

Get a clone of the native tools map.

Source

pub fn call_context(&self) -> Arc<Mutex<Option<LuaCallContext>>>

Get a clone of the call context handle.

Source

pub fn allowed_env(&self) -> Arc<Mutex<HashSet<String>>>

Get a clone of the allowed-env handle.

Source

pub fn allow_shell_exec(&self) -> Arc<AtomicBool>

Get whether imp.exec() calls are currently permitted.

Source

pub fn allow_http(&self) -> Arc<AtomicBool>

Get whether imp.http.* calls are currently permitted.

Source

pub fn allow_secrets(&self) -> Arc<AtomicBool>

Get whether secret access is currently permitted.

Source

pub fn allow_native_tool_calls(&self) -> Arc<AtomicBool>

Get whether imp.tool() calls are currently permitted.

Source

pub fn set_native_tools(&self, tools: HashMap<String, Arc<dyn Tool>>)

Populate the native tool registry (called once after tools are registered).

Source

pub fn set_call_context(&self, ctx: LuaCallContext)

Set the call context before executing a Lua tool function.

Source

pub fn clear_call_context(&self)

Clear the call context after execution.

Source

pub fn set_allowed_env(&self, vars: HashSet<String>)

Set the allowed env vars for this extension.

Source

pub fn set_allow_shell_exec(&self, allowed: bool)

Set whether imp.exec() calls are permitted for the current runtime.

Source

pub fn set_allow_http(&self, allowed: bool)

Set whether imp.http.* calls are permitted for the current runtime.

Source

pub fn set_allow_secrets(&self, allowed: bool)

Set whether secret access is permitted for the current runtime.

Source

pub fn set_allow_native_tool_calls(&self, allowed: bool)

Set whether imp.tool() calls are permitted for the current runtime.

Source

pub fn apply_capability_policy(&self, policy: &LuaCapabilityPolicy)

Apply a shipped-runtime capability policy.

Source

pub fn register_tool(&self, handle: LuaToolHandle)

Register a tool handle (called from bridge).

Source

pub fn register_hook(&self, handle: LuaHookHandle)

Register a hook handle (called from bridge).

Source

pub fn register_command(&self, handle: LuaCommandHandle)

Register a command handle (called from bridge).

Source

pub fn exec(&self, source: &str) -> Result<(), LuaError>

Execute a Lua script string.

Source

pub fn exec_file(&self, path: &Path) -> Result<(), LuaError>

Execute a Lua file.

Source

pub fn clear_registrations(&self)

Clear all registered tools, hooks, and commands.

Source

pub fn tool_count(&self) -> usize

Number of registered tools.

Source

pub fn hook_count(&self) -> usize

Number of registered hooks.

Source

pub fn command_count(&self) -> usize

Number of registered commands.

Source

pub fn tool_names(&self) -> Vec<String>

Get tool names.

Source

pub fn hook_events(&self) -> Vec<String>

Get hook event names.

Source

pub fn execute_command( &self, name: &str, args: &str, ) -> Result<Option<String>, LuaError>

Execute a registered command by name, returning its string output.

Returns Ok(None) if the command returned nil (silent success). Returns Ok(Some(text)) if the command returned a string or value. Returns Err if the command handler or name wasn’t found.

Source

pub fn execute_command_with_context( &self, name: &str, args: &str, call_ctx: Option<LuaCallContext>, ) -> Result<Option<String>, LuaError>

Execute a registered command with an optional host call context.

Source

pub fn command_names(&self) -> Vec<String>

Get command names.

Source

pub fn command_summaries(&self) -> Vec<(String, String)>

Get command names with descriptions for menus and discovery.

Source

pub fn has_command(&self, name: &str) -> bool

Check if a command with the given name exists.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,