Skip to main content

BuiltInRegistry

Struct BuiltInRegistry 

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

Registry for built-in objects and methods.

Manages all built-in JavaScript objects (Math, console, Array, etc.) and their methods. Supports plugin loading and method overrides.

§Examples

use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::EvalContext;

// Create registry with core built-ins
let registry = BuiltInRegistry::with_core();

// Use with evaluation context
let mut ctx = EvalContext::new();
ctx.install_core_builtins(registry);

Implementations§

Source§

impl BuiltInRegistry

Source

pub fn new() -> Self

Create an empty registry.

Use with_core instead to get a registry with standard built-in objects.

§Examples
use just::runner::plugin::registry::BuiltInRegistry;

let registry = BuiltInRegistry::new();
// Registry is empty, no built-ins registered
Source

pub fn with_core() -> Self

Create a registry with core built-in objects.

Includes: Math, console, JSON, String, Number, Array, Object, Error types. This is the most common way to create a registry.

§Examples
use just::parser::JsParser;
use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::EvalContext;
use just::runner::eval::statement::execute_statement;

let mut ctx = EvalContext::new();
ctx.install_core_builtins(BuiltInRegistry::with_core());

// Now you can use Math, console, etc.
let code = "var x = Math.abs(-42);";
let ast = JsParser::parse_to_ast_from_str(code).unwrap();
for stmt in &ast.body {
    execute_statement(stmt, &mut ctx).unwrap();
}
Source

pub fn register_object(&mut self, obj: BuiltInObject)

Register a custom built-in object.

Use this to add your own built-in objects to the registry.

§Examples
use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::BuiltInObject;

let mut registry = BuiltInRegistry::new();
let my_object = BuiltInObject::new("MyObject");
registry.register_object(my_object);
Source

pub fn get_object(&self, name: &str) -> Option<&BuiltInObject>

Get a registered object by name.

Returns None if the object is not registered.

§Examples
use just::runner::plugin::registry::BuiltInRegistry;

let registry = BuiltInRegistry::with_core();
let math = registry.get_object("Math");
assert!(math.is_some());
Source

pub fn get_object_mut(&mut self, name: &str) -> Option<&mut BuiltInObject>

Get a mutable reference to a registered object.

Source

pub fn override_method( &mut self, object: &str, method: &str, func: BuiltInFn, ) -> Result<(), PluginError>

Override an existing built-in method.

Source

pub fn get_method(&self, object: &str, method: &str) -> Option<&BuiltInFn>

Get a built-in function for execution.

Source

pub fn get_constructor(&self, object: &str) -> Option<&BuiltInFn>

Get a constructor function for an object.

Source

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

Check if an object exists in the registry.

Source

pub fn has_method(&self, object: &str, method: &str) -> bool

Check if a method exists on an object.

Source

pub fn load_native_plugin( &mut self, path: &Path, ) -> Result<PluginInfo, PluginError>

Load native plugin from dynamic library. Note: This is a placeholder - actual implementation requires unsafe FFI code and the libloading crate for cross-platform support.

Source

pub fn load_js_plugin(&mut self, path: &Path) -> Result<PluginInfo, PluginError>

Load JavaScript plugin from file. Note: This requires the runtime to be functional to execute the JS code.

Source

pub fn load_from_config( &mut self, config_path: &Path, ) -> Result<(), PluginError>

Load plugins from config file.

Source

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

Get list of all registered object names.

Source

pub fn loaded_plugins(&self) -> &[LoadedPlugin]

Get list of all loaded plugins.

Trait Implementations§

Source§

impl Default for BuiltInRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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