Skip to main content

LuaChild

Struct LuaChild 

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

A child entity implemented in Lua.

Can be used inside a LuaComponent to manage child entities.

§Lua Table Format

§Basic Child (no run capability)

{
    id = "child-1",
    status = "Idle",  -- Optional, defaults to "Idle"

    on_signal = function(sig)
        return "Handled" | "Ignored" | "Abort"
    end,

    abort = function()  -- Optional
    end,
}

§Runnable Child (with run capability)

{
    id = "worker-1",

    run = function(input)
        -- Perform work
        return { success = true, data = { result = input.value * 2 } }
    end,

    on_signal = function(sig)
        return "Handled"
    end,
}

Implementations§

Source§

impl LuaChild

Source

pub fn from_table( lua: Arc<Mutex<Lua>>, table: Table, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<Self, LuaError>

Creates a LuaChild from a Lua table.

§Arguments
  • lua - Shared Lua runtime
  • table - Lua table defining the child
  • sandbox - Sandbox policy for file operations and exec cwd
§Errors

Returns error if table is missing required fields.

Source

pub fn set_context(&mut self, context: Box<dyn ChildContext>)

Sets the runtime context for this child.

The context enables spawning sub-children and emitting output. Call this before running the child.

Source

pub fn has_context(&self) -> bool

Returns true if this child has a context set.

Source

pub fn from_table_runnable( lua: Arc<Mutex<Lua>>, table: Table, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<Self, LuaError>

Creates a LuaChild from a Lua table, requiring a run callback.

Use this when you need a RunnableChild that can execute work.

§Arguments
  • lua - Shared Lua runtime
  • table - Lua table defining the child (must have run function)
  • sandbox - Sandbox policy for file operations and exec cwd
§Errors

Returns error if table is missing required fields including run.

Source

pub fn is_runnable(&self) -> bool

Returns true if this child has a run callback (is runnable).

Source

pub fn simple( lua: Arc<Mutex<Lua>>, id: impl Into<String>, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<Self, LuaError>

Creates a simple LuaChild with just an ID.

The on_signal callback will return Ignored for all signals.

§Arguments
  • lua - Shared Lua runtime
  • id - Child identifier
  • sandbox - Sandbox policy for file operations and exec cwd
Source

pub fn from_script( lua: Arc<Mutex<Lua>>, script: &str, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<Self, LuaError>

Creates a LuaChild from inline script content.

The script should return a Lua table with the child definition.

§Arguments
  • lua - Shared Lua runtime
  • script - Inline Lua script
  • sandbox - Sandbox policy for file operations and exec cwd
§Errors

Returns error if script is invalid or missing required fields.

Trait Implementations§

Source§

impl Child for LuaChild

Source§

fn set_context(&mut self, ctx: Box<dyn ChildContext>)

Inject a ChildContext so the child can use orcs.* functions at runtime (RPC, exec, spawn, file tools, etc.). Read more
Source§

impl Identifiable for LuaChild

Source§

fn id(&self) -> &str

Returns the entity’s identifier. Read more
Source§

impl RunnableChild for LuaChild

Source§

fn run(&mut self, input: Value) -> ChildResult

Execute work with the given input (synchronous). Read more
Source§

impl SignalReceiver for LuaChild

Source§

fn on_signal(&mut self, signal: &Signal) -> SignalResponse

Handle an incoming signal. Read more
Source§

fn abort(&mut self)

Immediate abort. Read more
Source§

impl Statusable for LuaChild

Source§

fn status(&self) -> Status

Returns the current status. Read more
Source§

fn status_detail(&self) -> Option<StatusDetail>

Returns detailed status information. Read more
Source§

impl Send for LuaChild

Source§

impl Sync for LuaChild

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, 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> 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,