Skip to content

Commit ff4346f

Browse files
committed
fix failing tests and update docs
1 parent 54d8721 commit ff4346f

File tree

20 files changed

+133
-28
lines changed

20 files changed

+133
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@ required-features = ["lua54", "bevy/file_watcher", "bevy/multi_threaded"]
122122
panic = "deny"
123123
unwrap_used = "deny"
124124
expect_used = "deny"
125+
todo = "deny"

crates/bevy_mod_scripting_core/src/asset.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,7 @@ mod tests {
544544
type C = ();
545545
const LANGUAGE: Language = Language::Lua;
546546

547-
fn build_runtime() -> Self::R {
548-
todo!()
549-
}
547+
fn build_runtime() -> Self::R {}
550548
}
551549

552550
#[test]

crates/bevy_mod_scripting_core/src/bindings/world.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl WorldCallbackAccess {
124124
pub fn get_resource_type(
125125
&self,
126126
registration: ScriptTypeRegistration,
127-
) -> Result<Result<ScriptComponentRegistration, ScriptTypeRegistration>, InteropError> {
127+
) -> Result<Result<ScriptResourceRegistration, ScriptTypeRegistration>, InteropError> {
128128
let world = self.try_read()?;
129129
Ok(world.get_resource_type(registration))
130130
}
@@ -577,9 +577,9 @@ impl WorldAccessGuard<'_> {
577577
pub fn get_resource_type(
578578
&self,
579579
registration: ScriptTypeRegistration,
580-
) -> Result<ScriptComponentRegistration, ScriptTypeRegistration> {
580+
) -> Result<ScriptResourceRegistration, ScriptTypeRegistration> {
581581
match self.get_resource_id(registration.type_id()) {
582-
Some(resource_id) => Ok(ScriptComponentRegistration::new(registration, resource_id)),
582+
Some(resource_id) => Ok(ScriptResourceRegistration::new(registration, resource_id)),
583583
None => Err(registration),
584584
}
585585
}

crates/bevy_mod_scripting_core/src/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ mod tests {
192192

193193
const LANGUAGE: Language = Language::Lua;
194194

195-
fn build_runtime() -> Self::R {
196-
todo!()
197-
}
195+
fn build_runtime() -> Self::R {}
198196
}
199197

200198
#[test]

crates/bevy_mod_scripting_core/src/handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub(crate) fn handle_script_errors<I: Iterator<Item = ScriptError> + Clone>(
186186
}
187187

188188
#[cfg(test)]
189+
#[allow(clippy::todo)]
189190
mod test {
190191
use std::{borrow::Cow, collections::HashMap};
191192

crates/bevy_mod_scripting_functions/src/core.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ pub fn register_world_functions(reg: &mut World) -> Result<(), FunctionRegistrat
3838
Some(registration) => {
3939
let allocator = world.allocator();
4040

41-
let registration = match world.get_component_type(registration) {
42-
Ok(comp) => {
41+
let registration = match world.get_resource_type(registration) {
42+
Ok(res) => {
4343
let mut allocator = allocator.write();
4444
return Ok(Some(ReflectReference::new_allocated(
45-
comp,
45+
res,
4646
&mut allocator,
4747
)));
4848
}
4949
Err(registration) => registration,
5050
};
5151

52-
let registration = match world.get_resource_type(registration) {
53-
Ok(res) => {
52+
let registration = match world.get_component_type(registration) {
53+
Ok(comp) => {
5454
let mut allocator = allocator.write();
5555
return Ok(Some(ReflectReference::new_allocated(
56-
res,
56+
comp,
5757
&mut allocator,
5858
)));
5959
}

crates/languages/bevy_mod_scripting_lua/src/bindings/script_value.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl FromLua for LuaScriptValue {
5555
}
5656
ScriptValue::List(vec)
5757
}
58-
Value::Function(_) => todo!("Function FromLua is not implemented yet"),
5958
// Value::Thread(thread) => todo!(),
6059
Value::UserData(ud) => {
6160
let ud = ud.borrow::<LuaReflectReference>().map_err(|e| {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
local type = world._get_mock_type()
1+
local type = world._get_mock_resource_type()
22
assert(world.get_resource(type) == nil, "Resource should not exist")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ local received = {
1313
assert(type ~= nil, 'Type not found')
1414
assert(received.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. received.type_name)
1515
assert(received.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. received.short_name)
16+
17+
local type_ref = type:display_ref()
18+
-- check contains ScriptComponentRegistration
19+
assert(string.find(type_ref, "ScriptComponentRegistration") ~= nil, "ScriptComponentRegistration not found in type_ref. got: " .. type_ref)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local type = world.get_type_by_name('TestResource')
2+
3+
local expected = {
4+
type_name = 'test_utils::test_data::TestResource',
5+
short_name = 'TestResource',
6+
}
7+
8+
local received = {
9+
type_name = type:type_name(),
10+
short_name = type:short_name(),
11+
}
12+
13+
assert(type ~= nil, 'Type not found')
14+
assert(received.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. received.type_name)
15+
assert(received.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. received.short_name)
16+
local type_ref = type:display_ref()
17+
-- check contains ScriptResourceRegistration
18+
assert(string.find(type_ref, "ScriptResourceRegistration") ~= nil, "ScriptResourceRegistration not found in type_ref. got: " .. type_ref)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
local entity = world.spawn()
2-
local type = world._get_mock_type()
2+
local type = world._get_mock_component_type()
33

44
assert(world.has_component(entity, type) == false, "Entity should not have component")
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
local type = world._get_mock_type()
1+
local type = world._get_mock_resource_type()
22
assert(world.has_resource(type) == false, "Resource should not exist")

crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/no_resource_data_errors.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
local type = world._get_mock_type()
2+
local type = world._get_mock_resource_type()
33

44
assert_throws(function ()
55
world.remove_resource(type)

crates/script_integration_test_harness/src/test_functions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use bevy_mod_scripting_core::{
1313
script_function::{CallerContext, DynamicScriptFunctionMut},
1414
},
1515
pretty_print::DisplayWithWorld,
16-
ReflectReference, ScriptComponentRegistration, ScriptTypeRegistration, WorldCallbackAccess,
16+
ReflectReference, ScriptComponentRegistration, ScriptResourceRegistration,
17+
ScriptTypeRegistration, WorldCallbackAccess,
1718
},
1819
error::InteropError,
1920
};
@@ -46,7 +47,7 @@ pub fn register_test_functions(world: &mut App) {
4647
#[derive(Reflect)]
4748
struct Dummy;
4849
let reg = ScriptTypeRegistration::new(Arc::new(TypeRegistration::of::<Dummy>()));
49-
let comp = ScriptComponentRegistration::new(reg, ComponentId::new(999999999999999));
50+
let comp = ScriptResourceRegistration::new(reg, ComponentId::new(999999999999999));
5051
let allocator = world.allocator();
5152
let mut allocator = allocator.write();
5253
ReflectReference::new_allocated(comp, &mut allocator)

crates/xtask/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl Xtasks {
586586
Xtasks::Build => Self::build(app_settings),
587587
Xtasks::Check { ide_mode, kind } => Self::check(app_settings, ide_mode, kind),
588588
Xtasks::Docs { open, no_rust_docs } => Self::docs(app_settings, open, no_rust_docs),
589-
Xtasks::Test { name, package } => Self::test(app_settings, name, package),
589+
Xtasks::Test { name, package } => Self::test(app_settings, package, name),
590590
Xtasks::CiCheck => Self::cicd(app_settings),
591591
Xtasks::Init => Self::init(app_settings),
592592
Xtasks::Macros { macro_name } => match macro_name {
@@ -1135,11 +1135,14 @@ impl Xtasks {
11351135
test_args.push(name);
11361136
}
11371137

1138+
test_args.push("--exclude".to_owned());
1139+
test_args.push("xtask".to_owned());
1140+
11381141
Self::run_workspace_command(
11391142
&app_settings,
11401143
"test",
11411144
"Failed to run tests",
1142-
vec!["--exclude", "xtask"],
1145+
test_args,
11431146
None,
11441147
)?;
11451148

docs/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- [World](./ScriptingReference/world.md)
1818
- [ReflectReference](./ScriptingReference/reflect-reference.md)
1919
- [ScriptTypeRegistration](./ScriptingReference/script-type-registration.md)
20+
- [ScriptComponentRegistration](./ScriptingReference/script-component-registration.md)
21+
- [ScriptResourceRegistration](./ScriptingReference/script-resource-registration.md)
2022
- [ScriptQueryBuilder](./ScriptingReference/script-query-builder.md)
2123
- [ScriptQueryResult](./ScriptingReference/script-query-result.md)
2224
- [Core Callbacks](./ScriptingReference/core-callbacks.md)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ScriptComponentRegistration
2+
3+
A reference to a component type's registration, in general think of this as a handle to a type.
4+
5+
## type_name
6+
7+
Arguments:
8+
9+
| Argument | Type | Description |
10+
| --- | --- | --- |
11+
| `s` | `ScriptComponentRegistration` | The type registration as returned by `get_type_by_name` |
12+
13+
Returns:
14+
15+
| Return | Description |
16+
| --- | --- |
17+
| `String` | The type name |
18+
19+
```lua
20+
local name = MyType:type_name()
21+
```
22+
23+
## short_name
24+
25+
Arguments:
26+
27+
| Argument | Type | Description |
28+
| --- | --- | --- |
29+
| `s` | `ScriptComponentRegistration` | The type registration as returned by `get_type_by_name` |
30+
31+
Returns:
32+
33+
| Return | Description |
34+
| --- | --- |
35+
| `String` | The short name |
36+
37+
```lua
38+
local name = MyType:short_name()
39+
```

docs/src/ScriptingReference/script-query-builder.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Arguments:
1111
| Argument | Type | Description |
1212
| --- | --- | --- |
1313
| `s` | `ScriptQueryBuilder` | The query builder |
14-
| `component` | `ScriptTypeRegistration` | The component to query for |
14+
| `component` | `ScriptComponentRegistration` | The component to query for |
1515

1616
Returns:
1717

@@ -30,7 +30,7 @@ Arguments:
3030
| Argument | Type | Description |
3131
| --- | --- | --- |
3232
| `s` | `ScriptQueryBuilder` | The query builder |
33-
| `with` | `ScriptTypeRegistration` | The component to include in the query |
33+
| `with` | `ScriptComponentRegistration` | The component to include in the query |
3434

3535
Returns:
3636

@@ -49,7 +49,7 @@ Arguments:
4949
| Argument | Type | Description |
5050
| --- | --- | --- |
5151
| `s` | `ScriptQueryBuilder` | The query builder |
52-
| `without` | `ScriptTypeRegistration` | The component to exclude from the query |
52+
| `without` | `ScriptComponentRegistration` | The component to exclude from the query |
5353

5454
Returns:
5555

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ScriptResourceRegistration
2+
3+
A reference to a resource type's registration, in general think of this as a handle to a type.
4+
5+
## type_name
6+
7+
Arguments:
8+
9+
| Argument | Type | Description |
10+
| --- | --- | --- |
11+
| `s` | `ScriptResourceRegistration` | The type registration as returned by `get_type_by_name` |
12+
13+
Returns:
14+
15+
| Return | Description |
16+
| --- | --- |
17+
| `String` | The type name |
18+
19+
```lua
20+
local name = MyType:type_name()
21+
```
22+
23+
## short_name
24+
25+
Arguments:
26+
27+
| Argument | Type | Description |
28+
| --- | --- | --- |
29+
| `s` | `ScriptResourceRegistration` | The type registration as returned by `get_type_by_name` |
30+
31+
Returns:
32+
33+
| Return | Description |
34+
| --- | --- |
35+
| `String` | The short name |
36+
37+
```lua
38+
local name = MyType:short_name()
39+
```

docs/src/ScriptingReference/world.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The `World` is the entry point for interacting with `Bevy`. It is provided to sc
44

55
### get_type_by_name
66

7+
Returns either a `ScriptComponentRegistration` or `ScriptResourceRegistration` depending on the type of the type requested. If the type is neither returns a `ScriptTypeRegistration`.
8+
79
Arguments:
810

911
| Argument | Type | Description |
@@ -14,7 +16,7 @@ Returns:
1416

1517
| Return | Description |
1618
| --- | --- |
17-
| `Option<ScriptTypeRegistration>` | The type if it exists, otherwise `None` |
19+
| `Option<ScriptTypeRegistration OR scriptComponentRegistration OR scriptResourceRegistration>` | The registration for the type if it exists, otherwise `None` |
1820

1921
```lua
2022
MyType = world.get_type_by_name("MyType")

0 commit comments

Comments
 (0)