Skip to content

Commit 8a36f8f

Browse files
committed
Lua integration tests with some of the API's working!
1 parent 37eb231 commit 8a36f8f

23 files changed

+587
-397
lines changed

.rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# max_width = 60
22
# use_small_heuristics = "Max"
33
# format_generated_files = false
4+
5+
reorder_imports = true
6+
# currently unsupported but want them in when stable
7+
imports_granularity = "Crate"
8+
group_imports = "StdExternalCrate"

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.1",
7373
bevy = { version = "0.15.0-rc.3", default-features = false }
7474
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.8.0-alpha.1" }
7575
bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.8.0-alpha.1" }
76+
test_utils = { path = "crates/test_utils" }
7677

7778
[dev-dependencies]
7879
bevy = { workspace = true, default-features = true }
@@ -93,6 +94,7 @@ members = [
9394
"crates/languages/bevy_mod_scripting_rune",
9495
"crates/bevy_mod_scripting_common",
9596
"crates/bevy_mod_scripting_derive",
97+
"crates/test_utils",
9698
]
9799
resolver = "2"
98100
exclude = ["crates/bevy_api_gen", "crates/macro_tests"]

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ paste = "1.0.7"
2727
parking_lot = "0.12.1"
2828
lockable = "0.0.8"
2929
smallvec = "1.11"
30+
31+
[dev-dependencies]
32+
test_utils = { workspace = true }

crates/bevy_mod_scripting_core/src/bindings/query.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
1+
use super::{ReflectReference, WorldCallbackAccess};
2+
use crate::prelude::ScriptResult;
3+
use bevy::{
4+
ecs::{component::ComponentId, entity::Entity},
5+
reflect::TypeRegistration,
6+
};
17
use std::{any::TypeId, ops::Deref, sync::Arc};
28

3-
use bevy::{ecs::entity::Entity, reflect::TypeRegistration};
4-
5-
use super::{ReflectReference, WorldCallbackAccess, STALE_WORLD_MSG};
6-
use crate::prelude::{ScriptError, ScriptResult};
7-
89
/// A wrapper around a `TypeRegistration` that provides additional information about the type.
910
///
1011
/// This is used as a hook to a rust type from a scripting language. We should be able to easily convert between a type name and a [`ScriptTypeRegistration`].
1112
#[derive(Clone)]
12-
pub struct ScriptTypeRegistration(pub(crate) Arc<TypeRegistration>);
13+
pub struct ScriptTypeRegistration {
14+
pub(crate) registration: Arc<TypeRegistration>,
15+
pub component_id: Option<ComponentId>,
16+
}
1317

1418
impl ScriptTypeRegistration {
15-
pub fn new(arc: Arc<TypeRegistration>) -> Self {
16-
Self(arc)
19+
pub fn new(registration: Arc<TypeRegistration>, component_id: Option<ComponentId>) -> Self {
20+
Self {
21+
registration,
22+
component_id,
23+
}
1724
}
1825

1926
#[inline(always)]
2027
pub fn short_name(&self) -> &str {
21-
self.0.type_info().type_path_table().short_path()
28+
self.registration.type_info().type_path_table().short_path()
2229
}
2330

2431
#[inline(always)]
2532
pub fn type_name(&self) -> &'static str {
26-
self.0.type_info().type_path_table().path()
33+
self.registration.type_info().type_path_table().path()
2734
}
2835

2936
#[inline(always)]
3037
pub fn type_id(&self) -> TypeId {
31-
self.0.type_info().type_id()
38+
self.registration.type_info().type_id()
39+
}
40+
41+
#[inline(always)]
42+
pub fn component_id(&self) -> Option<ComponentId> {
43+
self.component_id
3244
}
3345
}
3446

3547
impl std::fmt::Debug for ScriptTypeRegistration {
3648
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3749
f.debug_tuple("ScriptTypeRegistration")
38-
.field(&self.0.type_info().type_path())
50+
.field(&self.registration.type_info().type_path())
3951
.finish()
4052
}
4153
}
4254

4355
impl std::fmt::Display for ScriptTypeRegistration {
4456
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45-
f.write_str(self.0.type_info().type_path())
46-
}
47-
}
48-
49-
impl Deref for ScriptTypeRegistration {
50-
type Target = Arc<TypeRegistration>;
51-
52-
fn deref(&self) -> &Self::Target {
53-
&self.0
57+
f.write_str(self.registration.type_info().type_path())
5458
}
5559
}
5660

crates/bevy_mod_scripting_core/src/bindings/reference.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use bevy::{
2828
},
2929
ptr::Ptr,
3030
reflect::{
31-
Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, TypeInfo, TypeRegistry
31+
Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError,
32+
TypeInfo, TypeRegistry,
3233
},
3334
};
3435
use smallvec::SmallVec;
@@ -59,7 +60,6 @@ pub struct ReflectReference {
5960
struct UnregisteredType;
6061

6162
impl ReflectReference {
62-
6363
pub fn new_allocated<T: PartialReflect>(
6464
value: T,
6565
allocator: &mut ReflectAllocator,
@@ -269,7 +269,8 @@ impl ReflectReference {
269269
allocator: Option<&ReflectAllocator>,
270270
) -> ScriptResult<&'w mut dyn PartialReflect> {
271271
if let ReflectBase::Owned(id) = &self.base.base_id {
272-
let allocator = allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?;
272+
let allocator =
273+
allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?;
273274

274275
let arc = allocator
275276
.get_mut(*id)
@@ -318,7 +319,10 @@ impl ReflectReference {
318319
Ok(current)
319320
}
320321

321-
fn walk_path_mut<'a>(&self, root: &'a mut dyn PartialReflect) -> ScriptResult<&'a mut dyn PartialReflect> {
322+
fn walk_path_mut<'a>(
323+
&self,
324+
root: &'a mut dyn PartialReflect,
325+
) -> ScriptResult<&'a mut dyn PartialReflect> {
322326
let mut current = root;
323327
for elem in self.reflect_path.iter() {
324328
current = elem
@@ -428,8 +432,12 @@ impl ReflectionPathElem {
428432

429433
impl<A: 'static, B: 'static> From<(A, B)> for DeferredReflection
430434
where
431-
A: Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync,
432-
B: Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + Send + Sync,
435+
A: Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>>
436+
+ Send
437+
+ Sync,
438+
B: Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>>
439+
+ Send
440+
+ Sync,
433441
{
434442
fn from((get, get_mut): (A, B)) -> Self {
435443
Self {
@@ -476,10 +484,15 @@ impl<'a> ReflectPath<'a> for &'a ReflectionPathElem {
476484
/// A ReflectPath which can perform arbitrary operations on the root object to produce a sub-reference
477485
#[derive(Clone)]
478486
pub struct DeferredReflection {
479-
pub get:
480-
Arc<dyn Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync>,
487+
pub get: Arc<
488+
dyn Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>>
489+
+ Send
490+
+ Sync,
491+
>,
481492
pub get_mut: Arc<
482-
dyn Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>>
493+
dyn Fn(
494+
&mut dyn PartialReflect,
495+
) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>>
483496
+ Send
484497
+ Sync,
485498
>,

0 commit comments

Comments
 (0)