Skip to content

Fixes the task.spawn, task.defer, and task.resume methods#874

Open
Vighnesh-V wants to merge 3 commits intoprimaryfrom
lute-task-fixes
Open

Fixes the task.spawn, task.defer, and task.resume methods#874
Vighnesh-V wants to merge 3 commits intoprimaryfrom
lute-task-fixes

Conversation

@Vighnesh-V
Copy link
Collaborator

@Vighnesh-V Vighnesh-V commented Mar 12, 2026

Resolves #522

This PR refactors task.spawn, defer, resume to share most of their logic for creating the stack and handing control off to newly created threads. The cause of the bug in #522 was that the stack didn't get set up correctly in the parent stack due to lua_xmove popping from the top, so the value that got returned was not callable with coroutine.status (because it wasn't a thread). The code I've added documents the invariant that I wanted to maintain along with helpers for correctly setting up the stack.

I've added tests for the following cases:
{task.defer, task.spawn, task.resume } called with { thread | function (except for task.resume, which only takes a thread passed { 0 arguments to resume with, > 0 arguments to resume with }.

I also introduced 'deferSelf' for the argumentless version of task.defer that says to immediately yield the current thread.

@Vighnesh-V Vighnesh-V self-assigned this Mar 12, 2026
@Vighnesh-V Vighnesh-V added the runtime Work in the C++ runtime portion of the code label Mar 12, 2026
@Vighnesh-V Vighnesh-V added this to the Release A milestone Mar 12, 2026
@Vighnesh-V Vighnesh-V marked this pull request as ready for review March 12, 2026 03:43
@Vighnesh-V Vighnesh-V force-pushed the lute-task-fixes branch 5 times, most recently from 8d3b645 to c0f86cc Compare March 12, 2026 16:20
Copy link
Contributor

@annieetang annieetang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for fixing these!

@Vighnesh-V Vighnesh-V requested a review from annieetang March 13, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime Work in the C++ runtime portion of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Result of task.spawn cannot be used with coroutine.status

2 participants