Skip to content

Commit 5bf2e68

Browse files
committed
Merge branch 'feat/improve-mdbook-generics-behaviour' of github.com:makspll/bevy_mod_scripting into feat/improve-mdbook-generics-behaviour
2 parents eb6082e + f5e733f commit 5bf2e68

File tree

24 files changed

+234
-54
lines changed

24 files changed

+234
-54
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.6...v0.9.7) - 2025-02-23
4+
5+
### Added
6+
7+
- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
8+
- add global functions to mdbook, allow documenting arguments and return values (#296)
9+
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)
10+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
11+
- pre-register reflected components with the world at finalize (#314)
12+
- add allocator diagnostics (#305)
13+
- improve warning on missing asset (#295)
14+
15+
### Fixed
16+
17+
- functions not releasing accesses correctly on error (#315)
18+
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)
19+
320
## [0.9.6](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.5...v0.9.6) - 2025-02-15
421

522
### Added

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting"
3-
version = "0.9.6"
3+
version = "0.9.7"
44
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -53,18 +53,18 @@ rhai = ["bevy_mod_scripting_rhai"]
5353
[dependencies]
5454
bevy = { workspace = true }
5555
bevy_mod_scripting_core = { workspace = true }
56-
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.6", optional = true }
57-
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.6", optional = true }
56+
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.7", optional = true }
57+
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.7", optional = true }
5858
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
5959
bevy_mod_scripting_functions = { workspace = true }
6060
bevy_mod_scripting_derive = { workspace = true }
6161

6262
[workspace.dependencies]
6363
profiling = { version = "1.0" }
6464
bevy = { version = "0.15.2", default-features = false }
65-
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.6" }
66-
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.6", default-features = false }
67-
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.9.6" }
65+
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.7" }
66+
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.7", default-features = false }
67+
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.9.7" }
6868

6969
# test utilities
7070
script_integration_test_harness = { path = "crates/testing_crates/script_integration_test_harness" }
@@ -77,7 +77,7 @@ rand = "0.8.5"
7777
bevy_console = "0.13"
7878
# rhai-rand = "0.1"
7979
ansi-parser = "0.9"
80-
ladfile_builder = { path = "crates/ladfile_builder", version = "0.2.0" }
80+
ladfile_builder = { path = "crates/ladfile_builder", version = "0.2.1" }
8181

8282
[workspace]
8383
members = [

badges/coverage.svg

Lines changed: 3 additions & 3 deletions
Loading

crates/bevy_mod_scripting_core/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_core-v0.9.6...bevy_mod_scripting_core-v0.9.7) - 2025-02-23
11+
12+
### Added
13+
14+
- pre-register reflected components with the world at finalize (#314)
15+
- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
16+
- add allocator diagnostics (#305)
17+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
18+
- improve warning on missing asset (#295)
19+
- add global functions to mdbook, allow documenting arguments and return values (#296)
20+
21+
### Fixed
22+
23+
- functions not releasing accesses correctly on error (#315)
24+
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)
25+
1026
## [0.9.6](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_core-v0.9.5...bevy_mod_scripting_core-v0.9.6) - 2025-02-15
1127

1228
### Fixed

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_core"
3-
version = "0.9.6"
3+
version = "0.9.7"
44
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -589,36 +589,39 @@ macro_rules! impl_script_function {
589589

590590
$( let $context = caller_context; )?
591591
let world = caller_context.world()?;
592-
world.begin_access_scope()?;
593-
let mut current_arg = 0;
594-
595-
$(
596-
current_arg += 1;
597-
let $param = args.pop_front();
598-
let $param = match $param {
599-
Some($param) => $param,
600-
None => {
601-
if let Some(default) = <$param>::default_value() {
602-
default
603-
} else {
604-
return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len));
605-
}
606-
}
607-
};
608-
let $param = <$param>::from_script($param, world.clone())
609-
.map_err(|e| InteropError::function_arg_conversion_error(current_arg.to_string(), e))?;
610-
)*
611-
612-
let ret = {
613-
let out = self( $( $context,)? $( $param.into(), )* );
614-
$(
615-
let $out = out?;
616-
let out = $out;
617-
)?
618-
out.into_script(world.clone()).map_err(|e| InteropError::function_arg_conversion_error("return value".to_owned(), e))
592+
// Safety: we're not holding any references to the world, the arguments which might have aliased will always be dropped
593+
let ret: Result<ScriptValue, InteropError> = unsafe {
594+
world.with_access_scope(||{
595+
let mut current_arg = 0;
596+
597+
$(
598+
current_arg += 1;
599+
let $param = args.pop_front();
600+
let $param = match $param {
601+
Some($param) => $param,
602+
None => {
603+
if let Some(default) = <$param>::default_value() {
604+
default
605+
} else {
606+
return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len));
607+
}
608+
}
609+
};
610+
let $param = <$param>::from_script($param, world.clone())
611+
.map_err(|e| InteropError::function_arg_conversion_error(current_arg.to_string(), e))?;
612+
)*
613+
614+
let ret = {
615+
let out = self( $( $context,)? $( $param.into(), )* );
616+
$(
617+
let $out = out?;
618+
let out = $out;
619+
)?
620+
out.into_script(world.clone()).map_err(|e| InteropError::function_arg_conversion_error("return value".to_owned(), e))
621+
};
622+
ret
623+
})?
619624
};
620-
// Safety: we're not holding any references to the world, the arguments which might have aliased have been dropped
621-
unsafe { world.end_access_scope()? };
622625
ret
623626
})();
624627
let script_value: ScriptValue = res.into();
@@ -695,6 +698,25 @@ mod test {
695698
});
696699
}
697700

701+
#[test]
702+
fn test_interrupted_call_releases_access_scope() {
703+
#[derive(bevy::prelude::Component, Reflect)]
704+
struct Comp;
705+
706+
let fn_ = |_a: crate::bindings::function::from::Mut<Comp>| 0usize;
707+
let script_function = fn_.into_dynamic_script_function().with_name("my_fn");
708+
709+
with_local_world(|| {
710+
let out =
711+
script_function.call(vec![ScriptValue::from(1)], FunctionCallContext::default());
712+
713+
assert!(out.is_err());
714+
let world = FunctionCallContext::default().world().unwrap();
715+
// assert no access is held
716+
assert!(world.list_accesses().is_empty());
717+
});
718+
}
719+
698720
#[test]
699721
fn test_overloaded_script_function() {
700722
let mut registry = ScriptFunctionRegistry::default();

crates/bevy_mod_scripting_core/src/bindings/world.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,22 @@ impl<'w> WorldAccessGuard<'w> {
123123
self.0.cell.replace(None);
124124
}
125125

126+
/// Runs a closure within an isolated access scope, releasing leftover accesses, should only be used in a single-threaded context.
127+
///
128+
/// Safety:
129+
/// - The caller must ensure it's safe to release any potentially locked accesses.
130+
pub(crate) unsafe fn with_access_scope<O, F: FnOnce() -> O>(
131+
&self,
132+
f: F,
133+
) -> Result<O, InteropError> {
134+
self.begin_access_scope()?;
135+
let o = f();
136+
unsafe { self.end_access_scope()? };
137+
Ok(o)
138+
}
139+
126140
/// Begins a new access scope. Currently this simply throws an erorr if there are any accesses held. Should only be used in a single-threaded context
127-
pub(crate) fn begin_access_scope(&self) -> Result<(), InteropError> {
141+
fn begin_access_scope(&self) -> Result<(), InteropError> {
128142
if self.0.accesses.count_accesses() != 0 {
129143
return Err(InteropError::invalid_access_count(self.0.accesses.count_accesses(), 0, "When beginning access scope, presumably for a function call, some accesses are still held".to_owned()));
130144
}
@@ -133,7 +147,7 @@ impl<'w> WorldAccessGuard<'w> {
133147
}
134148

135149
/// Ends the access scope, releasing all accesses. Should only be used in a single-threaded context
136-
pub(crate) unsafe fn end_access_scope(&self) -> Result<(), InteropError> {
150+
unsafe fn end_access_scope(&self) -> Result<(), InteropError> {
137151
self.0.accesses.release_all_accesses();
138152

139153
Ok(())

crates/bevy_mod_scripting_derive/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_derive-v0.9.6...bevy_mod_scripting_derive-v0.9.7) - 2025-02-23
11+
12+
### Added
13+
14+
- Add `TypedThrough` and `IntoScript` derive macros (#294)
15+
1016
## [0.9.4](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_derive-v0.9.3...bevy_mod_scripting_derive-v0.9.4) - 2025-02-12
1117

1218
### Added

crates/bevy_mod_scripting_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_derive"
3-
version = "0.9.6"
3+
version = "0.9.7"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"

crates/bevy_mod_scripting_functions/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_functions-v0.9.6...bevy_mod_scripting_functions-v0.9.7) - 2025-02-23
11+
12+
### Added
13+
14+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
15+
16+
### Fixed
17+
18+
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)
19+
1020
## [0.9.4](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_functions-v0.9.3...bevy_mod_scripting_functions-v0.9.4) - 2025-02-12
1121

1222
### Added

crates/bevy_mod_scripting_functions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_functions"
3-
version = "0.9.6"
3+
version = "0.9.7"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"

crates/lad_backends/mdbook_lad_preprocessor/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.1](https://github.com/makspll/bevy_mod_scripting/compare/mdbook_lad_preprocessor-v0.1.0...mdbook_lad_preprocessor-v0.1.1) - 2025-02-23
11+
12+
### Added
13+
14+
- add global functions to mdbook, allow documenting arguments and return values (#296)
15+
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)
16+
1017
## [0.1.0](https://github.com/makspll/bevy_mod_scripting/releases/tag/mdbook_lad_preprocessor-v0.1.0) - 2025-02-15
1118

1219
### Added

crates/lad_backends/mdbook_lad_preprocessor/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mdbook_lad_preprocessor"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"
@@ -15,7 +15,7 @@ readme = "readme.md"
1515
[dependencies]
1616
clap = "4"
1717
mdbook = "0.4"
18-
ladfile = { path = "../../ladfile", version = "0.2.0" }
18+
ladfile = { path = "../../ladfile", version = "0.3.0" }
1919
env_logger = "0.11"
2020
log = "0.4"
2121
serde_json = "1.0"

crates/ladfile/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.3.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.2.0-ladfile...v0.3.0-ladfile) - 2025-02-23
11+
12+
### Added
13+
14+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
15+
- add global functions to mdbook, allow documenting arguments and return values (#296)
16+
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)
17+
1018
## [0.2.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.1.1-ladfile...v0.2.0-ladfile) - 2025-02-15
1119

1220
### Added

crates/ladfile/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ladfile"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"

crates/ladfile_builder/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.2.1](https://github.com/makspll/bevy_mod_scripting/compare/v0.2.0-ladfile_builder...v0.2.1-ladfile_builder) - 2025-02-23
11+
12+
### Added
13+
14+
- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
15+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
16+
- add global functions to mdbook, allow documenting arguments and return values (#296)
17+
18+
### Fixed
19+
20+
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)

crates/ladfile_builder/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ladfile_builder"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"
@@ -17,7 +17,7 @@ bevy_mod_scripting_core = { workspace = true }
1717
# I don't think bevy has a top level feature for this :C
1818
bevy = { workspace = true }
1919
bevy_reflect = { version = "0.15.2", features = ["documentation"] }
20-
ladfile = { version = "0.2.0", path = "../ladfile" }
20+
ladfile = { version = "0.3.0", path = "../ladfile" }
2121
regex = "1.11"
2222

2323
[dev-dependencies]

crates/languages/bevy_mod_scripting_lua/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_lua-v0.9.6...bevy_mod_scripting_lua-v0.9.7) - 2025-02-23
11+
12+
### Added
13+
14+
- add `construct` global for constructing arbitrary types & `Union` type (#302)
15+
1016
## [0.9.2](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_lua-v0.9.1...bevy_mod_scripting_lua-v0.9.2) - 2025-02-08
1117

1218
### Fixed

crates/languages/bevy_mod_scripting_lua/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_lua"
3-
version = "0.9.6"
3+
version = "0.9.7"
44
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

0 commit comments

Comments
 (0)