This commit represents a major refactoring of our Rhai scripting system, transforming it from a factory-based approach to a more robust system-based architecture with improved hot reloading capabilities. Key Changes: - Renamed package from rhai_factory to rhai_system to better reflect its purpose - Renamed system_factory.rs to factory.rs for consistency and clarity - Implemented support for multiple script files in hot reloading - Added cross-script function calls, allowing functions in one script to call functions in another - Improved file watching to monitor all script files for changes - Enhanced error handling for script compilation failures - Simplified the API with a cleaner create_hot_reloadable_system function - Removed unused modules (error.rs, factory.rs, hot_reload_old.rs, module_cache.rs, relative_resolver.rs) - Updated all tests to work with the new architecture The new architecture: - Uses a System struct that holds references to script paths and provides a clean API - Compiles and merges multiple Rhai script files into a single AST - Automatically detects changes to any script file and recompiles them - Maintains thread safety with proper synchronization primitives - Provides better error messages when scripts fail to compile This refactoring aligns with our BasePathModuleResolver approach for module imports, making the resolution process more predictable and consistent. The hot reload example has been updated to demonstrate the new capabilities, showing how to: 1. Load and execute multiple script files 2. Watch for changes to these files 3. Automatically reload scripts when they change 4. Call functions across different script files All tests are passing, and the example demonstrates the improved functionality.
22 lines
654 B
Plaintext
22 lines
654 B
Plaintext
// This is a simple Rhai script that will be hot reloaded
|
|
// It contains functions that will be called by the main program
|
|
// It also uses functions from the utils.rhai script
|
|
|
|
// A simple greeting function
|
|
fn greet(name) {
|
|
// Use the format_greeting function from utils.rhai
|
|
let utils_greeting = format_greeting(name);
|
|
"Hello, " + name + "! This is the original script. " + utils_greeting
|
|
}
|
|
|
|
// A function to calculate the sum of two numbers
|
|
fn add(a, b) {
|
|
a + b
|
|
}
|
|
|
|
// A function that uses the calculate function from utils.rhai
|
|
fn advanced_calculation(x, y) {
|
|
// Use the calculate function from utils.rhai
|
|
calculate(x, y) * 2
|
|
}
|