Skip to content

feat: add ScriptValue override for printing opaque values #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl ReflectReferencePrinter {
}
id if id == TypeId::of::<char>() => downcast_case!(v, output, char),
id if id == TypeId::of::<bool>() => downcast_case!(v, output, bool),
id if id == TypeId::of::<ScriptValue>() => downcast_case!(v, output, ScriptValue),
_ => {
output.push_str(
v.get_represented_type_info()
Expand Down Expand Up @@ -654,7 +655,7 @@ impl<K: DisplayWithWorld + 'static, V: DisplayWithWorld + 'static> DisplayWithWo

#[cfg(test)]
mod test {
use bevy::prelude::AppTypeRegistry;
use bevy::{prelude::AppTypeRegistry, reflect::Reflect};

use crate::bindings::{
function::script_function::AppScriptFunctionRegistry, AppReflectAllocator,
Expand Down Expand Up @@ -778,4 +779,29 @@ mod test {

assert_eq!(map.display_value_with_world(world.clone()), "{hello: true}");
}

#[test]
fn test_script_value_in_reference() {
let mut world = setup_world();
let world = WorldGuard::new_exclusive(&mut world);

#[derive(Reflect)]
struct Test {
val: ScriptValue,
}

let test = Test {
val: ScriptValue::Bool(true),
};

let allocator = world.allocator();
let mut allocator_write = allocator.write();

let reflect_reference = ReflectReference::new_allocated(test, &mut allocator_write);
drop(allocator_write);
assert_eq!(
reflect_reference.display_value_with_world(world.clone()),
"{val: Reflect(ScriptValue(Bool(true)))}"
);
}
}
Loading