File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -189,10 +189,23 @@ where
189
189
let values = take ( & mut extra. as_mut ( ) . unwrap_unchecked ( ) . yielded_values ) ;
190
190
191
191
if !values. is_empty ( ) {
192
+ if raw. state ( ) == state {
193
+ // Edge case: main thread is being yielded
194
+ //
195
+ // We need to pop/clear stack early, then push args
196
+ ffi:: lua_pop ( state, -1 ) ;
197
+ }
198
+
192
199
match values. push_into_stack_multi ( raw) {
193
200
Ok ( nargs) => {
194
- ffi:: lua_pop ( state, -1 ) ;
195
- ffi:: lua_xmove ( raw. state ( ) , state, nargs) ;
201
+ // If not main thread, then clear and xmove to target thread
202
+ if raw. state ( ) != state {
203
+ // luau preserves the stack making yieldable continuations ugly and leaky
204
+ //
205
+ // Even outside of luau, clearing the stack is probably desirable
206
+ ffi:: lua_pop ( state, -1 ) ;
207
+ ffi:: lua_xmove ( raw. state ( ) , state, nargs) ;
208
+ }
196
209
return ffi:: lua_yield ( state, nargs) ;
197
210
}
198
211
Err ( err) => {
You can’t perform that action at this time.
0 commit comments