Skip to content

Commit

Permalink
Merge branch 'feat/improve-mdbook-generics-behaviour' of github.com:m…
Browse files Browse the repository at this point in the history
…akspll/bevy_mod_scripting into feat/improve-mdbook-generics-behaviour
  • Loading branch information
makspll committed Feb 23, 2025
2 parents eb6082e + f5e733f commit 5bf2e68
Show file tree
Hide file tree
Showing 24 changed files with 234 additions and 54 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## [0.9.7](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.6...v0.9.7) - 2025-02-23

### Added

- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
- add global functions to mdbook, allow documenting arguments and return values (#296)
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)
- add `construct` global for constructing arbitrary types & `Union` type (#302)
- pre-register reflected components with the world at finalize (#314)
- add allocator diagnostics (#305)
- improve warning on missing asset (#295)

### Fixed

- functions not releasing accesses correctly on error (#315)
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)

## [0.9.6](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.5...v0.9.6) - 2025-02-15

### Added
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting"
version = "0.9.6"
version = "0.9.7"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -53,18 +53,18 @@ rhai = ["bevy_mod_scripting_rhai"]
[dependencies]
bevy = { workspace = true }
bevy_mod_scripting_core = { workspace = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.6", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.6", optional = true }
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.7", optional = true }
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.7", optional = true }
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
bevy_mod_scripting_functions = { workspace = true }
bevy_mod_scripting_derive = { workspace = true }

[workspace.dependencies]
profiling = { version = "1.0" }
bevy = { version = "0.15.2", default-features = false }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.6" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.6", default-features = false }
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.9.6" }
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.7" }
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.7", default-features = false }
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.9.7" }

# test utilities
script_integration_test_harness = { path = "crates/testing_crates/script_integration_test_harness" }
Expand All @@ -77,7 +77,7 @@ rand = "0.8.5"
bevy_console = "0.13"
# rhai-rand = "0.1"
ansi-parser = "0.9"
ladfile_builder = { path = "crates/ladfile_builder", version = "0.2.0" }
ladfile_builder = { path = "crates/ladfile_builder", version = "0.2.1" }

[workspace]
members = [
Expand Down
6 changes: 3 additions & 3 deletions badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions crates/bevy_mod_scripting_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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

### Added

- pre-register reflected components with the world at finalize (#314)
- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
- add allocator diagnostics (#305)
- add `construct` global for constructing arbitrary types & `Union` type (#302)
- improve warning on missing asset (#295)
- add global functions to mdbook, allow documenting arguments and return values (#296)

### Fixed

- functions not releasing accesses correctly on error (#315)
- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)

## [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

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_core"
version = "0.9.6"
version = "0.9.7"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,36 +589,39 @@ macro_rules! impl_script_function {

$( let $context = caller_context; )?
let world = caller_context.world()?;
world.begin_access_scope()?;
let mut current_arg = 0;

$(
current_arg += 1;
let $param = args.pop_front();
let $param = match $param {
Some($param) => $param,
None => {
if let Some(default) = <$param>::default_value() {
default
} else {
return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len));
}
}
};
let $param = <$param>::from_script($param, world.clone())
.map_err(|e| InteropError::function_arg_conversion_error(current_arg.to_string(), e))?;
)*

let ret = {
let out = self( $( $context,)? $( $param.into(), )* );
$(
let $out = out?;
let out = $out;
)?
out.into_script(world.clone()).map_err(|e| InteropError::function_arg_conversion_error("return value".to_owned(), e))
// Safety: we're not holding any references to the world, the arguments which might have aliased will always be dropped
let ret: Result<ScriptValue, InteropError> = unsafe {
world.with_access_scope(||{
let mut current_arg = 0;

$(
current_arg += 1;
let $param = args.pop_front();
let $param = match $param {
Some($param) => $param,
None => {
if let Some(default) = <$param>::default_value() {
default
} else {
return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len));
}
}
};
let $param = <$param>::from_script($param, world.clone())
.map_err(|e| InteropError::function_arg_conversion_error(current_arg.to_string(), e))?;
)*

let ret = {
let out = self( $( $context,)? $( $param.into(), )* );
$(
let $out = out?;
let out = $out;
)?
out.into_script(world.clone()).map_err(|e| InteropError::function_arg_conversion_error("return value".to_owned(), e))
};
ret
})?
};
// Safety: we're not holding any references to the world, the arguments which might have aliased have been dropped
unsafe { world.end_access_scope()? };
ret
})();
let script_value: ScriptValue = res.into();
Expand Down Expand Up @@ -695,6 +698,25 @@ mod test {
});
}

#[test]
fn test_interrupted_call_releases_access_scope() {
#[derive(bevy::prelude::Component, Reflect)]
struct Comp;

let fn_ = |_a: crate::bindings::function::from::Mut<Comp>| 0usize;
let script_function = fn_.into_dynamic_script_function().with_name("my_fn");

with_local_world(|| {
let out =
script_function.call(vec![ScriptValue::from(1)], FunctionCallContext::default());

assert!(out.is_err());
let world = FunctionCallContext::default().world().unwrap();
// assert no access is held
assert!(world.list_accesses().is_empty());
});
}

#[test]
fn test_overloaded_script_function() {
let mut registry = ScriptFunctionRegistry::default();
Expand Down
18 changes: 16 additions & 2 deletions crates/bevy_mod_scripting_core/src/bindings/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,22 @@ impl<'w> WorldAccessGuard<'w> {
self.0.cell.replace(None);
}

/// Runs a closure within an isolated access scope, releasing leftover accesses, should only be used in a single-threaded context.
///
/// Safety:
/// - The caller must ensure it's safe to release any potentially locked accesses.
pub(crate) unsafe fn with_access_scope<O, F: FnOnce() -> O>(
&self,
f: F,
) -> Result<O, InteropError> {
self.begin_access_scope()?;
let o = f();
unsafe { self.end_access_scope()? };
Ok(o)
}

/// 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
pub(crate) fn begin_access_scope(&self) -> Result<(), InteropError> {
fn begin_access_scope(&self) -> Result<(), InteropError> {
if self.0.accesses.count_accesses() != 0 {
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()));
}
Expand All @@ -133,7 +147,7 @@ impl<'w> WorldAccessGuard<'w> {
}

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

Ok(())
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_mod_scripting_derive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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

### Added

- Add `TypedThrough` and `IntoScript` derive macros (#294)

## [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

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_derive"
version = "0.9.6"
version = "0.9.7"
edition = "2021"
authors = ["Maksymilian Mozolewski <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
10 changes: 10 additions & 0 deletions crates/bevy_mod_scripting_functions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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

### Added

- add `construct` global for constructing arbitrary types & `Union` type (#302)

### Fixed

- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)

## [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

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mod_scripting_functions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_functions"
version = "0.9.6"
version = "0.9.7"
edition = "2021"
authors = ["Maksymilian Mozolewski <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
7 changes: 7 additions & 0 deletions crates/lad_backends/mdbook_lad_preprocessor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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

### Added

- add global functions to mdbook, allow documenting arguments and return values (#296)
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)

## [0.1.0](https://github.com/makspll/bevy_mod_scripting/releases/tag/mdbook_lad_preprocessor-v0.1.0) - 2025-02-15

### Added
Expand Down
4 changes: 2 additions & 2 deletions crates/lad_backends/mdbook_lad_preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mdbook_lad_preprocessor"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Maksymilian Mozolewski <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -15,7 +15,7 @@ readme = "readme.md"
[dependencies]
clap = "4"
mdbook = "0.4"
ladfile = { path = "../../ladfile", version = "0.2.0" }
ladfile = { path = "../../ladfile", version = "0.3.0" }
env_logger = "0.11"
log = "0.4"
serde_json = "1.0"
Expand Down
8 changes: 8 additions & 0 deletions crates/ladfile/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.2.0-ladfile...v0.3.0-ladfile) - 2025-02-23

### Added

- add `construct` global for constructing arbitrary types & `Union` type (#302)
- add global functions to mdbook, allow documenting arguments and return values (#296)
- separate `ladfile` into `ladfile_builder` and `ladfile` crates (#293)

## [0.2.0](https://github.com/makspll/bevy_mod_scripting/compare/v0.1.1-ladfile...v0.2.0-ladfile) - 2025-02-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/ladfile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ladfile"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Maksymilian Mozolewski <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
20 changes: 20 additions & 0 deletions crates/ladfile_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.2.1](https://github.com/makspll/bevy_mod_scripting/compare/v0.2.0-ladfile_builder...v0.2.1-ladfile_builder) - 2025-02-23

### Added

- create `ScriptingDocgenPlugin` to allow exporting `LAD` files + export BMS bindings (#303)
- add `construct` global for constructing arbitrary types & `Union` type (#302)
- add global functions to mdbook, allow documenting arguments and return values (#296)

### Fixed

- remove `reflect_functions` and `file_watcher` flags from bevy dependency (#316)
4 changes: 2 additions & 2 deletions crates/ladfile_builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ladfile_builder"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Maksymilian Mozolewski <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -17,7 +17,7 @@ bevy_mod_scripting_core = { workspace = true }
# I don't think bevy has a top level feature for this :C
bevy = { workspace = true }
bevy_reflect = { version = "0.15.2", features = ["documentation"] }
ladfile = { version = "0.2.0", path = "../ladfile" }
ladfile = { version = "0.3.0", path = "../ladfile" }
regex = "1.11"

[dev-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions crates/languages/bevy_mod_scripting_lua/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [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

### Added

- add `construct` global for constructing arbitrary types & `Union` type (#302)

## [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

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/bevy_mod_scripting_lua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_mod_scripting_lua"
version = "0.9.6"
version = "0.9.7"
authors = ["Maksymilian Mozolewski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
Loading

0 comments on commit 5bf2e68

Please sign in to comment.