Skip to content

Commit 72388fa

Browse files
authored
feat: improved dynamic printing, adds ReflectDisplayWithTypeInfo for overriding opaque type printing (#478)
1 parent f60f33b commit 72388fa

File tree

73 files changed

+1431
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1431
-726
lines changed

Cargo.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
[package]
22
name = "bevy_mod_scripting"
3+
description = "Multi language scripting in Bevy"
4+
include = ["readme.md", "/src", "/examples", "/assets", "LICENSE", "/badges"]
5+
version.workspace = true
6+
edition.workspace = true
7+
authors.workspace = true
8+
license.workspace = true
9+
homepage.workspace = true
10+
repository.workspace = true
11+
keywords.workspace = true
12+
categories.workspace = true
13+
readme.workspace = true
14+
15+
[workspace.package]
316
version = "0.15.1"
4-
authors = ["Maksymilian Mozolewski <[email protected]>"]
517
edition = "2024"
18+
authors = ["Maksymilian Mozolewski <[email protected]>"]
619
license = "MIT OR Apache-2.0"
7-
description = "Multi language scripting in Bevy"
8-
repository = "https://github.com/makspll/bevy_mod_scripting"
920
homepage = "https://github.com/makspll/bevy_mod_scripting"
21+
repository = "https://github.com/makspll/bevy_mod_scripting"
1022
keywords = ["bevy", "gamedev", "scripting", "lua"]
1123
categories = ["game-development"]
1224
readme = "readme.md"
13-
include = ["readme.md", "/src", "/examples", "/assets", "LICENSE", "/badges"]
1425

1526
[lib]
1627
name = "bevy_mod_scripting"
@@ -292,6 +303,10 @@ name = "docgen"
292303
path = "examples/docgen.rs"
293304
required-features = []
294305

306+
[[example]]
307+
name = "runscript"
308+
path = "examples/run-script.rs"
309+
295310
[workspace.lints.clippy]
296311
panic = "deny"
297312
unwrap_used = "deny"

assets/tests/add_system/added_systems_run_in_parallel.lua

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@ digraph {
2727
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2828
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_asset::script_asset::ScriptAsset>::asset_events"];
2929
node_4 [label="bevy_mod_scripting_bindings::allocator::garbage_collector"];
30-
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
31-
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
32-
node_7 [label="on_test_post_update"];
33-
node_8 [label="custom_system_a"];
34-
node_9 [label="custom_system_b"];
35-
node_10 [label="SystemSet AssetEvents"];
36-
node_11 [label="SystemSet GarbageCollection"];
37-
node_12 [label="SystemSet ScriptSystem(custom_system_a)"];
38-
node_13 [label="SystemSet ScriptSystem(custom_system_b)"];
39-
node_0 -> node_10 [color=red, label="child of", arrowhead=diamond];
40-
node_1 -> node_10 [color=red, label="child of", arrowhead=diamond];
41-
node_2 -> node_10 [color=red, label="child of", arrowhead=diamond];
42-
node_3 -> node_10 [color=red, label="child of", arrowhead=diamond];
43-
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
44-
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
30+
node_5 [label="bevy_mod_scripting_core::handler::script_error_logger"];
31+
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
32+
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
33+
node_8 [label="on_test_post_update"];
34+
node_9 [label="custom_system_a"];
35+
node_10 [label="custom_system_b"];
36+
node_11 [label="SystemSet AssetEvents"];
37+
node_12 [label="SystemSet GarbageCollection"];
38+
node_13 [label="SystemSet ScriptSystem(custom_system_a)"];
39+
node_14 [label="SystemSet ScriptSystem(custom_system_b)"];
40+
node_0 -> node_11 [color=red, label="child of", arrowhead=diamond];
41+
node_1 -> node_11 [color=red, label="child of", arrowhead=diamond];
42+
node_2 -> node_11 [color=red, label="child of", arrowhead=diamond];
43+
node_3 -> node_11 [color=red, label="child of", arrowhead=diamond];
44+
node_4 -> node_12 [color=red, label="child of", arrowhead=diamond];
4545
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
46-
node_5 -> node_6 [color=blue, label="runs before", arrowhead=normal];
47-
node_7 -> node_8 [color=blue, label="runs before", arrowhead=normal];
48-
node_7 -> node_9 [color=blue, label="runs before", arrowhead=normal];
46+
node_10 -> node_14 [color=red, label="child of", arrowhead=diamond];
47+
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
48+
node_8 -> node_9 [color=blue, label="runs before", arrowhead=normal];
49+
node_8 -> node_10 [color=blue, label="runs before", arrowhead=normal];
4950
}
5051
]]
5152
assert_str_eq(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph")

assets/tests/add_system/added_systems_run_in_parallel.rhai

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@ digraph {
2626
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2727
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_asset::script_asset::ScriptAsset>::asset_events"];
2828
node_4 [label="bevy_mod_scripting_bindings::allocator::garbage_collector"];
29-
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
30-
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
31-
node_7 [label="on_test_post_update"];
32-
node_8 [label="custom_system_a"];
33-
node_9 [label="custom_system_b"];
34-
node_10 [label="SystemSet AssetEvents"];
35-
node_11 [label="SystemSet GarbageCollection"];
36-
node_12 [label="SystemSet ScriptSystem(custom_system_a)"];
37-
node_13 [label="SystemSet ScriptSystem(custom_system_b)"];
38-
node_0 -> node_10 [color=red, label="child of", arrowhead=diamond];
39-
node_1 -> node_10 [color=red, label="child of", arrowhead=diamond];
40-
node_2 -> node_10 [color=red, label="child of", arrowhead=diamond];
41-
node_3 -> node_10 [color=red, label="child of", arrowhead=diamond];
42-
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
43-
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
29+
node_5 [label="bevy_mod_scripting_core::handler::script_error_logger"];
30+
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
31+
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
32+
node_8 [label="on_test_post_update"];
33+
node_9 [label="custom_system_a"];
34+
node_10 [label="custom_system_b"];
35+
node_11 [label="SystemSet AssetEvents"];
36+
node_12 [label="SystemSet GarbageCollection"];
37+
node_13 [label="SystemSet ScriptSystem(custom_system_a)"];
38+
node_14 [label="SystemSet ScriptSystem(custom_system_b)"];
39+
node_0 -> node_11 [color=red, label="child of", arrowhead=diamond];
40+
node_1 -> node_11 [color=red, label="child of", arrowhead=diamond];
41+
node_2 -> node_11 [color=red, label="child of", arrowhead=diamond];
42+
node_3 -> node_11 [color=red, label="child of", arrowhead=diamond];
43+
node_4 -> node_12 [color=red, label="child of", arrowhead=diamond];
4444
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
45-
node_5 -> node_6 [color=blue, label="runs before", arrowhead=normal];
46-
node_7 -> node_8 [color=blue, label="runs before", arrowhead=normal];
47-
node_7 -> node_9 [color=blue, label="runs before", arrowhead=normal];
45+
node_10 -> node_14 [color=red, label="child of", arrowhead=diamond];
46+
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
47+
node_8 -> node_9 [color=blue, label="runs before", arrowhead=normal];
48+
node_8 -> node_10 [color=blue, label="runs before", arrowhead=normal];
4849
}`;
4950

5051
assert_str_eq.call(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph");

assets/tests/display/print_value_by_default.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ReflectReference {
4545
),
4646
base_id: Resource(
4747
ComponentId(
48-
"test_utils::test_data::TestResource",
48+
test_utils::test_data::TestResource,
4949
),
5050
),
5151
},

crates/bevy_mod_scripting_asset/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "bevy_mod_scripting_asset"
3-
version = "0.15.1"
4-
authors = ["Maksymilian Mozolewski <[email protected]>"]
5-
edition = "2024"
6-
license = "MIT OR Apache-2.0"
73
description = "Core traits and structures required for other parts of bevy_mod_scripting"
8-
repository = "https://github.com/makspll/bevy_mod_scripting"
9-
homepage = "https://github.com/makspll/bevy_mod_scripting"
10-
categories = ["game-development"]
11-
readme = "readme.md"
12-
4+
version.workspace = true
5+
edition.workspace = true
6+
authors.workspace = true
7+
license.workspace = true
8+
homepage.workspace = true
9+
repository.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
12+
readme.workspace = true
1313

1414
[dependencies]
1515
bevy_reflect = { workspace = true }

crates/bevy_mod_scripting_asset/readme.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

crates/bevy_mod_scripting_asset/src/language.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ pub enum Language {
2121

2222
impl std::fmt::Display for Language {
2323
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24-
match self {
25-
Language::Rhai => "Rhai".fmt(f),
26-
Language::Lua => "Lua".fmt(f),
27-
Language::Rune => "Rune".fmt(f),
28-
Language::External(cow) => cow.fmt(f),
29-
Language::Unknown => "Unknown".fmt(f),
24+
Cow::<'static, str>::from(self).fmt(f)
25+
}
26+
}
27+
28+
impl From<&Language> for Cow<'static, str> {
29+
fn from(val: &Language) -> Self {
30+
match val {
31+
Language::Rhai => Cow::Borrowed("Rhai"),
32+
Language::Lua => Cow::Borrowed("Lua"),
33+
Language::Rune => Cow::Borrowed("Rune"),
34+
Language::External(cow) => cow.clone(),
35+
Language::Unknown => Cow::Borrowed("Unknown"),
3036
}
3137
}
3238
}

crates/bevy_mod_scripting_bindings/Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[package]
22
name = "bevy_mod_scripting_bindings"
3-
version = "0.15.1"
4-
authors = ["Maksymilian Mozolewski <[email protected]>"]
5-
edition = "2024"
6-
license = "MIT OR Apache-2.0"
7-
description = "Core traits and structures required for other parts of bevy_mod_scripting"
8-
repository = "https://github.com/makspll/bevy_mod_scripting"
9-
homepage = "https://github.com/makspll/bevy_mod_scripting"
10-
categories = ["game-development"]
11-
readme = "readme.md"
3+
description = "Core traits and structures required for smoothly interfacing with other languages in a generic way"
4+
version.workspace = true
5+
edition.workspace = true
6+
authors.workspace = true
7+
license.workspace = true
8+
homepage.workspace = true
9+
repository.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
12+
readme.workspace = true
1213

1314

1415
[dependencies]

crates/bevy_mod_scripting_bindings/src/access_map.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,26 @@ impl DisplayWithTypeInfo for ReflectAccessId {
109109
fn display_with_type_info(
110110
&self,
111111
f: &mut std::fmt::Formatter<'_>,
112-
_type_info_provider: Option<&dyn GetTypeInfo>,
112+
type_info_provider: Option<&dyn GetTypeInfo>,
113113
) -> std::fmt::Result {
114114
match self.kind {
115115
ReflectAccessKind::ComponentOrResource => {
116116
write!(
117117
f,
118118
"Component or resource: {}",
119-
WithTypeInfo(&ComponentId::new(self.id as usize))
119+
WithTypeInfo::new_with_opt_info(
120+
&ComponentId::new(self.id as usize),
121+
type_info_provider
122+
)
120123
)
121124
}
122125
ReflectAccessKind::Allocation => write!(
123126
f,
124127
"Allocation to: {}",
125-
WithTypeInfo(&ReflectAllocationId::new(self.id))
128+
WithTypeInfo::new_with_opt_info(
129+
&ReflectAllocationId::new(self.id),
130+
type_info_provider
131+
)
126132
),
127133
ReflectAccessKind::Global => write!(f, "World(Global)"),
128134
}
@@ -221,23 +227,15 @@ impl ReflectAccessId {
221227
}
222228
}
223229

224-
#[profiling::all_functions]
225230
impl From<ComponentId> for ReflectAccessId {
226-
fn from(value: ComponentId) -> Self {
227-
Self {
228-
kind: ReflectAccessKind::ComponentOrResource,
229-
id: value.index() as u64,
230-
}
231+
fn from(id: ComponentId) -> Self {
232+
ReflectAccessId::for_component_id(id)
231233
}
232234
}
233235

234-
#[profiling::all_functions]
235236
impl From<ReflectAllocationId> for ReflectAccessId {
236-
fn from(value: ReflectAllocationId) -> Self {
237-
Self {
238-
kind: ReflectAccessKind::Allocation,
239-
id: value.id(),
240-
}
237+
fn from(id: ReflectAllocationId) -> Self {
238+
ReflectAccessId::for_allocation(id)
241239
}
242240
}
243241

crates/bevy_mod_scripting_bindings/src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ impl DebugWithTypeInfo for ReflectAllocation {
119119
fn to_string_with_type_info(
120120
&self,
121121
f: &mut std::fmt::Formatter<'_>,
122-
_type_info_provider: Option<&dyn bevy_mod_scripting_display::GetTypeInfo>,
122+
type_info_provider: Option<&dyn bevy_mod_scripting_display::GetTypeInfo>,
123123
) -> std::fmt::Result {
124-
f.debug_tuple_with_type_info("ReflectAllocation")
124+
f.debug_tuple_with_type_info("ReflectAllocation", type_info_provider)
125125
.field(&((self.0.get() as *mut ()) as usize))
126126
.finish()
127127
}

0 commit comments

Comments
 (0)