From fd30dbda7801512c8733c26f1a912f0cc7b86af8 Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 23 Mar 2025 20:02:22 +0000 Subject: [PATCH 1/2] fix: fix global type cache not containing generic types --- assets/tests/globals/type_cache_available.lua | 4 ++++ assets/tests/globals/type_cache_available.rhai | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/assets/tests/globals/type_cache_available.lua b/assets/tests/globals/type_cache_available.lua index f9cc8435dc..3d99c77a24 100644 --- a/assets/tests/globals/type_cache_available.lua +++ b/assets/tests/globals/type_cache_available.lua @@ -3,4 +3,8 @@ function on_test() local my_type = types.TestResource; assert(my_type ~= nil, "Type TestResource is not available in type cache"); assert(my_type:short_name() == "TestResource", "Type t.TestResource:short_name() is not correct: " .. my_type:short_name()); + + local my_generic_type = types["GenericComponent"]; + assert(my_generic_type ~= nil, "Type GenericComponent is not available in type cache"); + assert(my_generic_type:short_name() == "GenericComponent", "Type t.GenericComponent:short_name() is not correct: " .. my_generic_type:short_name()); end \ No newline at end of file diff --git a/assets/tests/globals/type_cache_available.rhai b/assets/tests/globals/type_cache_available.rhai index ff736a7afb..fd01920c74 100644 --- a/assets/tests/globals/type_cache_available.rhai +++ b/assets/tests/globals/type_cache_available.rhai @@ -2,4 +2,8 @@ fn on_test() { let my_type = types.TestResource; assert(type_of(my_type) != "()", "Type TestResource is not available in type cache"); assert(my_type.short_name.call() == "TestResource", "Type t.TestResource:short_name() is not correct: " + my_type.short_name.call()); + + let my_type = types["GenericComponent"]; + assert(type_of(my_type) != "()", "Type GenericComponent is not available in type cache"); + assert(my_type.short_name.call() == "GenericComponent", "Type t.GenericComponent:short_name() is not correct: " + my_type.short_name.call()); } \ No newline at end of file From 3d09fdf23cd19ec8d61daabd964ada642e856870 Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 23 Mar 2025 20:03:37 +0000 Subject: [PATCH 2/2] fix --- .../src/bindings/globals/core.rs | 13 +++++---- .../src/lib.rs | 27 ------------------- .../test_utils/src/test_data.rs | 21 ++++++++++++--- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/crates/bevy_mod_scripting_core/src/bindings/globals/core.rs b/crates/bevy_mod_scripting_core/src/bindings/globals/core.rs index 202ae6ea70..394fe4d6b3 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/globals/core.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/globals/core.rs @@ -87,13 +87,12 @@ impl CoreGlobals { let type_registry = type_registry.read(); let mut type_cache = HashMap::::default(); for registration in type_registry.iter() { - if let Some(ident) = registration.type_info().type_path_table().ident() { - let registration = ScriptTypeRegistration::new(Arc::new(registration.clone())); - let registration = guard.clone().get_type_registration(registration)?; - let registration = - registration.map_both(Val::from, |u| u.map_both(Val::from, Val::from)); - type_cache.insert(ident.to_string(), registration); - } + let type_path = registration.type_info().type_path_table().short_path(); + let registration = ScriptTypeRegistration::new(Arc::new(registration.clone())); + let registration = guard.clone().get_type_registration(registration)?; + let registration = + registration.map_both(Val::from, |u| u.map_both(Val::from, Val::from)); + type_cache.insert(type_path.to_owned(), registration); } Ok(type_cache) diff --git a/crates/testing_crates/script_integration_test_harness/src/lib.rs b/crates/testing_crates/script_integration_test_harness/src/lib.rs index 0518ec05d8..81209056eb 100644 --- a/crates/testing_crates/script_integration_test_harness/src/lib.rs +++ b/crates/testing_crates/script_integration_test_harness/src/lib.rs @@ -38,33 +38,6 @@ fn dummy_startup_system() {} fn dummy_before_post_update_system() {} fn dummy_post_update_system() {} -pub trait Benchmarker: 'static + Send + Sync { - fn bench( - &self, - label: &str, - f: &dyn Fn() -> Result, - ) -> Result; - - fn clone_box(&self) -> Box; -} - -#[derive(Clone)] -pub struct NoOpBenchmarker; - -impl Benchmarker for NoOpBenchmarker { - fn bench( - &self, - _label: &str, - f: &dyn Fn() -> Result, - ) -> Result { - f() - } - - fn clone_box(&self) -> Box { - Box::new(self.clone()) - } -} - #[derive(Event)] struct TestEventFinished; diff --git a/crates/testing_crates/test_utils/src/test_data.rs b/crates/testing_crates/test_utils/src/test_data.rs index 59bb5bf0f0..fea49718d7 100644 --- a/crates/testing_crates/test_utils/src/test_data.rs +++ b/crates/testing_crates/test_utils/src/test_data.rs @@ -23,6 +23,20 @@ impl TestComponent { } } +#[derive(Component, Reflect, PartialEq, Eq, Debug, Default)] +#[reflect(Component)] +pub struct GenericComponent { + pub value: T, +} + +impl GenericComponent { + pub fn init() -> Self { + Self { + value: "Initial Value".to_string(), + } + } +} + /// Test Resource with Reflect and ReflectResource registered #[derive(Resource, Reflect, Default, PartialEq, Eq, Debug)] #[reflect(Resource)] @@ -278,11 +292,12 @@ impl_test_component_ids!( SimpleStruct => 6, SimpleTupleStruct => 7, SimpleEnum => 8, + GenericComponent => 9, ], [ - TestResource => 9, - ResourceWithDefault => 10, - TestResourceWithVariousFields => 11, + TestResource => 10, + ResourceWithDefault => 11, + TestResourceWithVariousFields => 12, ] );