-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat!: re-design GetTypeDependencies
trait & add GetTypeDependencies
derive macro
#369
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e05e626
to
30323b9
Compare
…s script arguments
27455ba
to
7383302
Compare
GetTypeDependencies
trait allowing more complex script argument types
GetTypeDependencies
trait allowing more complex script argument typesGetTypeDependencies
trait & Add smart derive macro.
GetTypeDependencies
trait & Add smart derive macro.GetTypeDependencies
trait & Add derive macro.
GetTypeDependencies
trait & Add derive macro.GetTypeDependencies
trait & add derive macro.
GetTypeDependencies
trait & add derive macro.GetTypeDependencies
trait & add derive macro
GetTypeDependencies
trait & add derive macroGetTypeDependencies
trait & add GetTypeDependencies
derive macro
Merged
makspll
added a commit
that referenced
this pull request
Mar 15, 2025
) # Summary using `get_type_by_name` is slightly cumbersome. In order to not repeat yourself AND avoid polluting globals, you need to call: ```lua local Type = world.get_type_by_name("MYType") ``` in EVERY callback, or alternatively do it once at the top of your script, but doing that goes against the advice to not run code in the body of the script outside of any functions. this PR adds a global `types` cache, which lets you do: ```lua types.MyType ``` or for more complex types: ```lua types["MyGenericType<MyOtherType>"] ``` The types populated in the cache are equivalent to the types available as static globals with the addition of generic types. The change makes use of changes in #369 to correctly type this global as `HashMap<String, ScriptComponentRegistration | ScriptResourceRegistration | ScriptTypeRegistration >` meaning once we start generating decleration files for lua we will have the correct types at hand # Migration Guide - Not a breaking change, but you should change instances where you call `get_type_by_name("T")` to `types["T"]` etc. this will increase performance as well as make your scripts easier to read!
makspll
added a commit
that referenced
this pull request
Mar 16, 2025
## 🤖 New release * `bevy_mod_scripting_derive`: 0.9.11 -> 0.10.0 * `bevy_mod_scripting_core`: 0.9.11 -> 0.10.0 (✓ API compatible changes) * `bevy_mod_scripting_lua`: 0.9.11 -> 0.10.0 (✓ API compatible changes) * `bevy_mod_scripting_rhai`: 0.9.11 -> 0.10.0 (✓ API compatible changes) * `bevy_mod_scripting_functions`: 0.9.11 -> 0.10.0 (✓ API compatible changes) * `ladfile`: 0.3.1 -> 0.4.0 (⚠ API breaking changes) * `mdbook_lad_preprocessor`: 0.1.3 -> 0.1.4 (✓ API compatible changes) * `ladfile_builder`: 0.2.5 -> 0.2.6 (✓ API compatible changes) * `bevy_mod_scripting`: 0.9.11 -> 0.10.0 (✓ API compatible changes) ### ⚠ `ladfile` breaking changes ```text --- failure constructible_struct_adds_field: externally-constructible struct adds field --- Description: A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field. ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron Failed in: field LadInstance.type_kind in /tmp/.tmpHaT0UL/bevy_mod_scripting/crates/ladfile/src/lib.rs:97 --- failure enum_missing: pub enum removed or renamed --- Description: A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_missing.ron Failed in: enum ladfile::LadArgumentKind, previously in file /tmp/.tmpAHPNdG/ladfile/src/lib.rs:171 --- failure struct_pub_field_missing: pub struct's pub field removed or renamed --- Description: A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely. ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/struct_pub_field_missing.ron Failed in: field type_id of struct LadInstance, previously in file /tmp/.tmpAHPNdG/ladfile/src/lib.rs:97 ``` <details><summary><i><b>Changelog</b></i></summary><p> ## `bevy_mod_scripting_derive` <blockquote> ## [0.10.0](bevy_mod_scripting_derive-v0.9.11...bevy_mod_scripting_derive-v0.10.0) - 2025-03-16 ### Added - [**breaking**] re-design `GetTypeDependencies` trait & add `GetTypeDependencies` derive macro ([#369](#369)) </blockquote> ## `bevy_mod_scripting_core` <blockquote> ## [0.10.0](bevy_mod_scripting_core-v0.9.11...bevy_mod_scripting_core-v0.10.0) - 2025-03-16 ### Added - *(ladfile)* improve globals in LAD format ([#372](#372)) - add global `types` cache making `get_type_by_name` redundant ([#370](#370)) - [**breaking**] re-design `GetTypeDependencies` trait & add `GetTypeDependencies` derive macro ([#369](#369)) - shorten import paths ([#367](#367)) - Add missing `luau` extension, improve extension configuration options ([#366](#366)) - allow lua scripts to insert `ScriptComponent`'s ([#359](#359)) - ✨ Parallelizable Script Systems with `Res` and `Query` parameters & Schedule debugging utilities ([#361](#361)) ### Fixed - supported extensions not including default extensions [SKIP_CHANGELOG] ([#373](#373)) - unit enum variants other than `Option::None` being converted into `ScriptValue::Unit` ([#360](#360)) ### Other - [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove `Sync` bound from Contexts ([#350](#350)) </blockquote> ## `bevy_mod_scripting_lua` <blockquote> ## [0.10.0](bevy_mod_scripting_lua-v0.9.11...bevy_mod_scripting_lua-v0.10.0) - 2025-03-16 ### Added - Add missing `luau` extension, improve extension configuration options ([#366](#366)) ### Fixed - [**breaking**] script contexts being completely overwritten on a re-load ([#345](#345)) ### Other - [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove `Sync` bound from Contexts ([#350](#350)) </blockquote> ## `bevy_mod_scripting_rhai` <blockquote> ## [0.10.0](bevy_mod_scripting_rhai-v0.9.11...bevy_mod_scripting_rhai-v0.10.0) - 2025-03-16 ### Added - Add missing `luau` extension, improve extension configuration options ([#366](#366)) - ✨ Parallelizable Script Systems with `Res` and `Query` parameters & Schedule debugging utilities ([#361](#361)) ### Fixed - rhai reloading behavior regression from #345 [SKIP_CHANGELOG] ([#351](#351)) - [**breaking**] script contexts being completely overwritten on a re-load ([#345](#345)) ### Other - [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove `Sync` bound from Contexts ([#350](#350)) </blockquote> ## `bevy_mod_scripting_functions` <blockquote> ## [0.10.0](bevy_mod_scripting_functions-v0.9.11...bevy_mod_scripting_functions-v0.10.0) - 2025-03-16 ### Added - add global `types` cache making `get_type_by_name` redundant ([#370](#370)) - ✨ Parallelizable Script Systems with `Res` and `Query` parameters & Schedule debugging utilities ([#361](#361)) </blockquote> ## `ladfile` <blockquote> ## [0.4.0](v0.3.1-ladfile...v0.4.0-ladfile) - 2025-03-16 ### Added - *(ladfile)* improve globals in LAD format ([#372](#372)) </blockquote> ## `mdbook_lad_preprocessor` <blockquote> ## [0.1.4](v0.1.3-mdbook_lad_preprocessor...v0.1.4-mdbook_lad_preprocessor) - 2025-03-16 ### Added - *(ladfile)* improve globals in LAD format ([#372](#372)) </blockquote> ## `ladfile_builder` <blockquote> ## [0.2.6](v0.2.5-ladfile_builder...v0.2.6-ladfile_builder) - 2025-03-16 ### Added - *(ladfile)* improve globals in LAD format ([#372](#372)) </blockquote> ## `bevy_mod_scripting` <blockquote> ## [0.10.0](v0.9.11...v0.10.0) - 2025-03-16 ### Added - add global `types` cache making `get_type_by_name` redundant ([#370](#370)) - ✨ Parallelizable Script Systems with `Res` and `Query` parameters & Schedule debugging utilities ([#361](#361)) - Add missing `luau` extension, improve extension configuration options ([#366](#366)) - *(ladfile)* improve globals in LAD format ([#372](#372)) - [**breaking**] re-design `GetTypeDependencies` trait & add `GetTypeDependencies` derive macro ([#369](#369)) - shorten import paths ([#367](#367)) - allow lua scripts to insert `ScriptComponent`'s ([#359](#359)) ### Fixed - rhai reloading behavior regression from #345 [SKIP_CHANGELOG] ([#351](#351)) - [**breaking**] script contexts being completely overwritten on a re-load ([#345](#345)) - supported extensions not including default extensions [SKIP_CHANGELOG] ([#373](#373)) - unit enum variants other than `Option::None` being converted into `ScriptValue::Unit` ([#360](#360)) ### Other - [**breaking**] Merge `ScriptContexts<T>` into `Scripts<T>` + Remove `Sync` bound from Contexts ([#350](#350)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Maksymilian Mozolewski <[email protected]>
This was referenced Mar 16, 2025
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently the
GetTypeDependencies
trait struggles with deeply nested container types.For example
HashMap<Result<T,E>,V>
would place bounds ofGetTypeRegistration
onResult
which quickly falls apart with non-'static
types likeRef
andMut
which don't haveGetTypeRegistration
implementations.This overhaul introduces the concept of an
Underlying
type allowing us to have two type trees, theReal
types which we want to end up being registered in the registry, and theFacade
types which exist purely as trait carriers:Thanks to that we can make the two assertions confidently:
Typed
and possible to add to the type registryAlso previously,
HashMap<T, Val<T>>
would not registerHashMap<T, T>
correctly at all, meaning we now get better dependency coverage!Migration Guide
GetTypeDependencies
for manually, will need to specify an underlying type, for non-generic types this will just beSelf
, for types which have recursive registrations, this will beSelf<T1::Underlying, T2::Underlying...>
etc