Skip to main content

ScriptLoader

Struct ScriptLoader 

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

Script loader with configurable search paths.

Search order: configured search paths in order added.

Implementations§

Source§

impl ScriptLoader

Source

pub fn new(sandbox: Arc<dyn SandboxPolicy>) -> Self

Creates a new loader.

The sandbox is passed to all components loaded by this loader.

Source

pub fn with_path(self, path: impl AsRef<Path>) -> Self

Adds a search path.

Paths are searched in the order they are added.

Source

pub fn with_project_root(self, root: impl AsRef<Path>) -> Self

Adds project root’s scripts/ directory to search paths.

Convenience method for with_path(root.join("scripts")).

Source

pub fn with_paths( self, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self

Adds multiple search paths.

Source

pub fn search_paths(&self) -> &[PathBuf]

Returns configured search paths.

Source

pub fn load(&self, name: &str) -> Result<LuaComponent, LuaError>

Loads a script by name.

Search order:

  1. Each search path: {path}/{name}.lua (single file)
  2. Each search path: {path}/{name}/init.lua (directory with co-located modules)

Directory-based loading sets up package.path so that standard require() resolves co-located modules within the component directory.

§Errors

Returns error if script not found in any location.

Source

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

Lists all available script names.

Includes scripts from all search paths and embedded (if enabled).

Source

pub fn load_all(&self) -> LoadResult

Loads all scripts from configured search paths.

Scans each search path for .lua files and attempts to load them. Errors are collected as warnings, not propagated—allowing partial success.

§Example
let loader = ScriptLoader::new()
    .with_path("~/.orcs/scripts")
    .with_path(".orcs/scripts");

let result = loader.load_all();

// Log warnings but continue
for warn in &result.warnings {
    eprintln!("Warning: {}", warn);
}

// Use loaded components
for (name, component) in result.loaded {
    println!("Loaded: {}", name);
}
Source

pub fn load_dir(path: &Path, sandbox: Arc<dyn SandboxPolicy>) -> LoadResult

Loads all scripts from a single directory.

Convenience method equivalent to:

ScriptLoader::new(sandbox)
    .with_path(path)
    .load_all()
Source

pub fn load_file<P: AsRef<Path>>( path: P, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<LuaComponent, LuaError>

Loads a script from a specific file path.

§Errors

Returns error if file not found or invalid.

Source

pub fn crate_scripts_dir() -> PathBuf

Returns the crate’s built-in scripts directory.

This is the scripts/ directory relative to the crate root. Mainly useful for development and testing.

Trait Implementations§

Source§

impl Clone for ScriptLoader

Source§

fn clone(&self) -> ScriptLoader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScriptLoader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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,