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
impl LuaChild
Sourcepub fn from_table(
lua: Arc<Mutex<Lua>>,
table: Table,
sandbox: Arc<dyn SandboxPolicy>,
) -> Result<Self, LuaError>
pub fn from_table( lua: Arc<Mutex<Lua>>, table: Table, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<Self, LuaError>
Sourcepub fn set_context(&mut self, context: Box<dyn ChildContext>)
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.
Sourcepub fn has_context(&self) -> bool
pub fn has_context(&self) -> bool
Returns true if this child has a context set.
Sourcepub fn from_table_runnable(
lua: Arc<Mutex<Lua>>,
table: Table,
sandbox: Arc<dyn SandboxPolicy>,
) -> Result<Self, LuaError>
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 runtimetable- Lua table defining the child (must haverunfunction)sandbox- Sandbox policy for file operations and exec cwd
§Errors
Returns error if table is missing required fields including run.
Sourcepub fn is_runnable(&self) -> bool
pub fn is_runnable(&self) -> bool
Returns true if this child has a run callback (is runnable).
Sourcepub fn simple(
lua: Arc<Mutex<Lua>>,
id: impl Into<String>,
sandbox: Arc<dyn SandboxPolicy>,
) -> Result<Self, LuaError>
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 runtimeid- Child identifiersandbox- Sandbox policy for file operations and exec cwd
Sourcepub fn from_script(
lua: Arc<Mutex<Lua>>,
script: &str,
sandbox: Arc<dyn SandboxPolicy>,
) -> Result<Self, LuaError>
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 runtimescript- Inline Lua scriptsandbox- 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
impl Child for LuaChild
Source§fn set_context(&mut self, ctx: Box<dyn ChildContext>)
fn set_context(&mut self, ctx: Box<dyn ChildContext>)
ChildContext so the child can use orcs.* functions at
runtime (RPC, exec, spawn, file tools, etc.). Read moreSource§impl Identifiable for LuaChild
impl Identifiable for LuaChild
Source§impl RunnableChild for LuaChild
impl RunnableChild for LuaChild
Source§impl SignalReceiver for LuaChild
impl SignalReceiver for LuaChild
Source§impl Statusable for LuaChild
impl Statusable for LuaChild
impl Send for LuaChild
impl Sync for LuaChild
Auto Trait Implementations§
impl Freeze for LuaChild
impl !RefUnwindSafe for LuaChild
impl Unpin for LuaChild
impl UnsafeUnpin for LuaChild
impl !UnwindSafe for LuaChild
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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