何十日間の激闘ついに完全解決!"Everything is Plugin"哲学実装達成🚀 🏆 核心成果: - FactoryPolicy システム完全実装 (StrictPluginFirst/CompatPluginFirst/BuiltinFirst) - プラグイン優先をデフォルト化: plugins > user > builtin - builtin_impls/ 分離実装でPhase 2削除準備完了 - unified_registry.rs でwith_env_policy()によるポリシー制御 - 環境変数制御: NYASH_BOX_FACTORY_POLICY=strict_plugin_first 🔧 技術実装: - src/box_factory/mod.rs: FactoryPolicy enum + rebuild_cache() + policy-based ordering - src/box_factory/builtin.rs: builtin_impls/への振り分け実装 - src/box_factory/builtin_impls/: 7ファイル分離 (削除順序コメント付き) - src/runtime/unified_registry.rs: with_env_policy() でStrictPluginFirst デフォルト ✅ 動作確認完了: - StringBox プラグイン優先で作成成功 - Factory Policy: StrictPluginFirst メッセージ確認 - プラグイン初期化確認 (Net plugin, FileBox plugin) 📋 Phase 2準備完了: builtin_impls/ 段階削除戦略 1. string_box.rs, integer_box.rs (プラグイン準備済み) 2. bool_box.rs (プラグイン要作成) 3. array_box.rs, map_box.rs (プラグイン確認要) 4. console_box.rs (最後 - ログ用に重要) 🎯 ChatGPT戦略 + ユーザー分離アイデアの完璧な統合実装成果! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
2.2 KiB
Rust
63 lines
2.2 KiB
Rust
/*!
|
|
* Global Unified Box Registry
|
|
*
|
|
* Manages the global instance of UnifiedBoxRegistry
|
|
* Integrates all Box creation sources (builtin, user-defined, plugin)
|
|
*/
|
|
|
|
use crate::box_factory::builtin::BuiltinBoxFactory;
|
|
#[cfg(feature = "plugins")]
|
|
use crate::box_factory::plugin::PluginBoxFactory;
|
|
use crate::box_factory::{UnifiedBoxRegistry, FactoryPolicy};
|
|
use std::sync::{Arc, Mutex, OnceLock};
|
|
|
|
/// Global registry instance
|
|
static GLOBAL_REGISTRY: OnceLock<Arc<Mutex<UnifiedBoxRegistry>>> = OnceLock::new();
|
|
|
|
/// Initialize the global unified registry
|
|
pub fn init_global_unified_registry() {
|
|
GLOBAL_REGISTRY.get_or_init(|| {
|
|
// Phase 15.5: Use environment variable policy (StrictPluginFirst for "Everything is Plugin")
|
|
let mut registry = UnifiedBoxRegistry::with_env_policy();
|
|
// Default: enable builtins unless building with feature "plugins-only"
|
|
#[cfg(not(feature = "plugins-only"))]
|
|
{
|
|
registry.register(std::sync::Arc::new(BuiltinBoxFactory::new()));
|
|
}
|
|
|
|
// Register plugin Box factory (primary)
|
|
#[cfg(feature = "plugins")]
|
|
{
|
|
registry.register(Arc::new(PluginBoxFactory::new()));
|
|
}
|
|
|
|
// TODO: User-defined Box factory will be registered by interpreter
|
|
|
|
// Phase 15.5: FactoryPolicy determines actual priority order
|
|
// StrictPluginFirst: plugins > user > builtin (SOLVES StringBox/IntegerBox issue)
|
|
// BuiltinFirst: builtin > user > plugin (legacy default)
|
|
|
|
Arc::new(Mutex::new(registry))
|
|
});
|
|
}
|
|
|
|
/// Get the global unified registry
|
|
pub fn get_global_unified_registry() -> Arc<Mutex<UnifiedBoxRegistry>> {
|
|
init_global_unified_registry();
|
|
GLOBAL_REGISTRY.get().unwrap().clone()
|
|
}
|
|
|
|
/// Register a user-defined Box factory (called by interpreter)
|
|
pub fn register_user_defined_factory(factory: Arc<dyn crate::box_factory::BoxFactory>) {
|
|
let registry = get_global_unified_registry();
|
|
let mut registry_lock = registry.lock().unwrap();
|
|
|
|
// Insert at position 1 (after builtin, before plugin)
|
|
// This maintains priority: builtin > user > plugin
|
|
if registry_lock.factories.len() >= 2 {
|
|
registry_lock.factories.insert(1, factory);
|
|
} else {
|
|
registry_lock.register(factory);
|
|
}
|
|
}
|