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
impl ScriptLoader
Sourcepub fn new(sandbox: Arc<dyn SandboxPolicy>) -> Self
pub fn new(sandbox: Arc<dyn SandboxPolicy>) -> Self
Creates a new loader.
The sandbox is passed to all components loaded by this loader.
Sourcepub fn with_path(self, path: impl AsRef<Path>) -> Self
pub fn with_path(self, path: impl AsRef<Path>) -> Self
Adds a search path.
Paths are searched in the order they are added.
Sourcepub fn with_project_root(self, root: impl AsRef<Path>) -> Self
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")).
Sourcepub fn with_paths(
self,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self
pub fn with_paths( self, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self
Adds multiple search paths.
Sourcepub fn search_paths(&self) -> &[PathBuf]
pub fn search_paths(&self) -> &[PathBuf]
Returns configured search paths.
Sourcepub fn load(&self, name: &str) -> Result<LuaComponent, LuaError>
pub fn load(&self, name: &str) -> Result<LuaComponent, LuaError>
Loads a script by name.
Search order:
- Each search path:
{path}/{name}.lua(single file) - 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.
Sourcepub fn list_available(&self) -> Vec<String>
pub fn list_available(&self) -> Vec<String>
Lists all available script names.
Includes scripts from all search paths and embedded (if enabled).
Sourcepub fn load_all(&self) -> LoadResult
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);
}Sourcepub fn load_dir(path: &Path, sandbox: Arc<dyn SandboxPolicy>) -> LoadResult
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()Sourcepub fn load_file<P: AsRef<Path>>(
path: P,
sandbox: Arc<dyn SandboxPolicy>,
) -> Result<LuaComponent, LuaError>
pub fn load_file<P: AsRef<Path>>( path: P, sandbox: Arc<dyn SandboxPolicy>, ) -> Result<LuaComponent, LuaError>
Sourcepub fn crate_scripts_dir() -> PathBuf
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
impl Clone for ScriptLoader
Source§fn clone(&self) -> ScriptLoader
fn clone(&self) -> ScriptLoader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ScriptLoader
impl !RefUnwindSafe for ScriptLoader
impl Send for ScriptLoader
impl Sync for ScriptLoader
impl Unpin for ScriptLoader
impl UnsafeUnpin for ScriptLoader
impl !UnwindSafe for ScriptLoader
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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