#interpreter #scripting #javascript #javascript-interpreter #rust #nativeobjects

aloe-script

A simple and lightweight JavaScript interpreter for Rust, allowing basic scripting with integration to native objects through DynamicObject classes. This crate is a translation of the c++ juce module serving the same function.

1 unstable release

Uses new Rust 2024

new 0.1.1 Apr 4, 2025

#5 in #javascript-interpreter


Used in aloe-exports

GPL-3.0 license

1MB
7.5K SLoC

Aloe-Script

Aloe-Script is a minimalistic JavaScript interpreter designed for embedded scripting capabilities in Rust applications. While it doesn't aim for full ECMAScript compliance or high execution speeds like JIT-compiled engines, Aloe-Script excels in compactness and simplicity, interfacing smoothly with native Rust objects via the DynamicObject architecture.

Key Features

  • Lightweight Interpreter: Offers basic JavaScript execution without the overhead of larger engines.
  • Native Object Integration: Seamlessly integrates with Rust objects, allowing dynamic interaction between script and host application.
  • Core Arithmetic and Logic Operations: Supports a wide range of operators, including arithmetic, logical, and bitwise operations.
  • JSON Support: Provides functionality to convert JSON text to and from native data structures.
  • Customizable Execution: Set maximum execution times to prevent runaway scripts.

Usage

  1. Initialization: Instantiate a JavascriptEngine and register any necessary native objects.

    let mut engine = JavascriptEngine::default();
    engine.register_native_object("myObject", &mut my_dynamic_object);
    
  2. Script Execution: Execute JavaScript code with the execute() method and retrieve results with evaluate().

    engine.execute(&"console.log('Hello, Aloe-Script!')".to_string());
    let result = engine.evaluate(&"2 + 2".to_string(), &mut None);
    
  3. Native Function Calls: Directly call functions within the script environment using call_function().

    let return_val = engine.call_function("myFunction", &args, &mut None);
    

Considerations

  • Reference Counting: Uses reference counting instead of garbage collection, which can lead to cyclic dependency issues.
  • Performance: Not intended for heavy computational tasks; best suited for lightweight scripting requirements.

Requirements

  • Rust 2024 Edition

License

Licensed under GPL-3.0.


Please note: This README.md was generated by an AI model and may not be 100% accurate. However, it should provide a good overview of the crate's functionality.

This crate is a translation of the JUCE module.

JUCE is a c++ software framework for developing high performance audio applications.

Usage falls under the GPLv3 as well as the JUCE commercial license.

See github.com/juce-framework/JUCE and the JUCE license page for details.

This crate is in the process of being translated from c++ to rust. For progress updates, please see the workspacer rust project. designed specifically for rust projects.

Dependencies

~13–27MB
~378K SLoC