@@ -173,14 +173,50 @@ impl Thread {
173173 }
174174 }
175175
176+ /// Resumes execution of this thread, immediately raising an error.
177+ ///
178+ /// This is a Luau specific extension.
179+ #[ cfg( feature = "luau" ) ]
180+ #[ cfg_attr( docsrs, doc( cfg( feature = "luau" ) ) ) ]
181+ pub fn resume_error < R > ( & self , error : impl crate :: IntoLua ) -> Result < R >
182+ where
183+ R : FromLuaMulti ,
184+ {
185+ let lua = self . 0 . lua . lock ( ) ;
186+ match self . status_inner ( & lua) {
187+ ThreadStatusInner :: New ( _) | ThreadStatusInner :: Yielded ( _) => { }
188+ _ => return Err ( Error :: CoroutineUnresumable ) ,
189+ } ;
190+
191+ let state = lua. state ( ) ;
192+ let thread_state = self . state ( ) ;
193+ unsafe {
194+ let _sg = StackGuard :: new ( state) ;
195+ let _thread_sg = StackGuard :: with_top ( thread_state, 0 ) ;
196+
197+ check_stack ( state, 1 ) ?;
198+ error. push_into_stack ( & lua) ?;
199+ ffi:: lua_xmove ( state, thread_state, 1 ) ;
200+
201+ let ( _, nresults) = self . resume_inner ( & lua, ffi:: LUA_RESUMEERROR ) ?;
202+ check_stack ( state, nresults + 1 ) ?;
203+ ffi:: lua_xmove ( thread_state, state, nresults) ;
204+
205+ R :: from_stack_multi ( nresults, & lua)
206+ }
207+ }
208+
176209 /// Resumes execution of this thread.
177210 ///
178211 /// It's similar to `resume()` but leaves `nresults` values on the thread stack.
179212 unsafe fn resume_inner ( & self , lua : & RawLua , nargs : c_int ) -> Result < ( ThreadStatusInner , c_int ) > {
180213 let state = lua. state ( ) ;
181214 let thread_state = self . state ( ) ;
182215 let mut nresults = 0 ;
216+ #[ cfg( not( feature = "luau" ) ) ]
183217 let ret = ffi:: lua_resume ( thread_state, state, nargs, & mut nresults as * mut c_int ) ;
218+ #[ cfg( feature = "luau" ) ]
219+ let ret = ffi:: lua_resumex ( thread_state, state, nargs, & mut nresults as * mut c_int ) ;
184220 match ret {
185221 ffi:: LUA_OK => Ok ( ( ThreadStatusInner :: Finished , nresults) ) ,
186222 ffi:: LUA_YIELD => Ok ( ( ThreadStatusInner :: Yielded ( 0 ) , nresults) ) ,
0 commit comments