feat: add send feature flag for thread-safe Lua state#30
Open
danielsreichenbach wants to merge 3 commits intomainfrom
Open
feat: add send feature flag for thread-safe Lua state#30danielsreichenbach wants to merge 3 commits intomainfrom
send feature flag for thread-safe Lua state#30danielsreichenbach wants to merge 3 commits intomainfrom
Conversation
Introduce a `send` cargo feature that makes `Lua` implement `Send`, enabling use in multi-threaded contexts like bevy_mod_scripting. When enabled: - `ProtoRef` switches from `Rc<Proto>` to `Arc<Proto>` - `UserDataBox` switches from `Box<dyn Any>` to `Box<dyn Any + Send>` - `GcRef<T>` gains `Send + Sync` (index-only, no pointer data) - `IoFile` and `DynLib` gain `Send` impls - `unsafe impl Send for Lua` is provided All existing tests pass in both configurations. The send feature adds one compile-time test asserting `Lua: Send`. Closes #29
Add public API methods needed by bevy_mod_scripting integration: - Table::from_gc_ref, Function::from_gc_ref, AnyUserData::from_gc_ref - Lua::table_next for table iteration - Lua::val_as_bytes for string value access
Provides a public API for borrowing typed data from AnyUserData handles without exposing the internal LuaState. Needed by external integrations that work with userdata through the high-level Lua API.
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
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
sendthat makesLuaimplementSendChanges
When
sendis enabled:ProtoReftype alias switches fromRc<Proto>toArc<Proto>UserDataBoxtype alias switches fromBox<dyn Any>toBox<dyn Any + Send>GcRef<T>gainsSend + Sync(index-only, no pointer data)IoFileandDynLibgainSendimplsunsafe impl Send for Luais provided21 files changed across the codebase to use the new type aliases instead of direct
Rc<Proto>references.Closes #29
Test plan
cargo fmt -- --checkpassescargo clippy --all-targetspasses (0 warnings)cargo clippy --all-targets --features sendpasses (0 warnings)cargo testpasses (1323 tests)cargo test --features sendpasses (1324 tests, +1lua_is_sendcompile-time assertion)cargo doc --no-depspasses