Add resume_error to Thread for luau#513
Closed
cheesycod wants to merge 5 commits intomlua-rs:devfrom
Anti-Raid:dev
Closed
Add resume_error to Thread for luau#513cheesycod wants to merge 5 commits intomlua-rs:devfrom Anti-Raid:dev
cheesycod wants to merge 5 commits intomlua-rs:devfrom
Anti-Raid:dev
Conversation
08ec1c3 to
c975660
Compare
Author
|
@khvzak This PR is now ready for review. Have moved the resume error test to the tests/thread.rs file like the other thread tests |
Author
|
Oh, its already merged to mlua main, am closing this PR |
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.
This adds support for the Luau specific
lua_resumeerrorto mlua dev branch as Thread::resume_error which allows directly resuming a thread with a bubbled up error which is at the top of the threads stack. This can be useful for many situations including resuming coroutine yields but as a bubbled up error with working pcall etc.This C API is increasingly used by luau runtimes for error handling in threads which is how I found out about it:
Hence why I made a pr for mlua to add it @khvzak
The API in question takes in a single argument of type IntoLua which is pushed to top of thread stack. Resume error is called and gettop is used to get the results and then IntoLuaMulti is used to convert to desired value.
For sample usage of this API:
Without lua_resumeerror, doing the above requires monkeypatching coroutine.yield to get errors to correctly bubble which then breaks pcall. With lua_resumeerror, the above just works with fully working error propagation and pcall fully working as desired (and is also more performant).
Also, merging this PR would solve the original issue of #500 regarding erroring yielded threads. It turns out
lua_resumeerroris the Luau solution for this.