@@ -356,36 +356,37 @@ impl Lua {
356356 // The returned value then pushed onto the stack.
357357 #[ doc( hidden) ]
358358 #[ cfg( not( tarpaulin_include) ) ]
359- pub unsafe fn entrypoint < F , A , R > ( self , state : * mut ffi:: lua_State , func : F ) -> c_int
359+ pub unsafe fn entrypoint < F , A , R > ( state : * mut ffi:: lua_State , func : F ) -> c_int
360360 where
361- F : Fn ( & Lua , A ) -> Result < R > + MaybeSend + ' static ,
361+ F : FnOnce ( & Lua , A ) -> Result < R > ,
362362 A : FromLuaMulti ,
363363 R : IntoLua ,
364364 {
365- let extra = self . lock ( ) . extra . get ( ) ;
366- // `self` is no longer needed and must be dropped at this point to avoid possible memory leak
365+ // Make sure that Lua is initialized
366+ let mut lua = Self :: init_from_ptr ( state) ;
367+ lua. collect_garbage = false ;
368+ // `Lua` is no longer needed and must be dropped at this point to avoid possible memory leak
367369 // in case of possible longjmp (lua_error) below
368- drop ( self ) ;
369-
370- callback_error_ext ( state, extra, move |nargs| {
371- let lua = ( * extra) . lua ( ) ;
372- let rawlua = lua. lock ( ) ;
373- let _guard = StateGuard :: new ( & rawlua, state) ;
374- let args = A :: from_stack_args ( nargs, 1 , None , & rawlua) ?;
375- func ( lua, args) ?. push_into_stack ( & rawlua) ?;
370+ drop ( lua) ;
371+
372+ callback_error_ext ( state, ptr:: null_mut ( ) , move |extra, nargs| {
373+ let rawlua = ( * extra) . raw_lua ( ) ;
374+ let _guard = StateGuard :: new ( rawlua, state) ;
375+ let args = A :: from_stack_args ( nargs, 1 , None , rawlua) ?;
376+ func ( rawlua. lua ( ) , args) ?. push_into_stack ( rawlua) ?;
376377 Ok ( 1 )
377378 } )
378379 }
379380
380381 // A simple module entrypoint without arguments
381382 #[ doc( hidden) ]
382383 #[ cfg( not( tarpaulin_include) ) ]
383- pub unsafe fn entrypoint1 < R , F > ( self , state : * mut ffi:: lua_State , func : F ) -> c_int
384+ pub unsafe fn entrypoint1 < F , R > ( state : * mut ffi:: lua_State , func : F ) -> c_int
384385 where
386+ F : FnOnce ( & Lua ) -> Result < R > ,
385387 R : IntoLua ,
386- F : Fn ( & Lua ) -> Result < R > + MaybeSend + ' static ,
387388 {
388- self . entrypoint ( state, move |lua, _: ( ) | func ( lua) )
389+ Self :: entrypoint ( state, move |lua, _: ( ) | func ( lua) )
389390 }
390391
391392 /// Skips memory checks for some operations.
@@ -575,8 +576,7 @@ impl Lua {
575576 // We don't support GC interrupts since they cannot survive Lua exceptions
576577 return ;
577578 }
578- let extra = ExtraData :: get ( state) ;
579- let result = callback_error_ext ( state, extra, move |_| {
579+ let result = callback_error_ext ( state, ptr:: null_mut ( ) , move |extra, _| {
580580 let interrupt_cb = ( * extra) . interrupt_callback . clone ( ) ;
581581 let interrupt_cb = mlua_expect ! ( interrupt_cb, "no interrupt callback set in interrupt_proc" ) ;
582582 if Rc :: strong_count ( & interrupt_cb) > 2 {
@@ -629,7 +629,7 @@ impl Lua {
629629
630630 unsafe extern "C-unwind" fn warn_proc ( ud : * mut c_void , msg : * const c_char , tocont : c_int ) {
631631 let extra = ud as * mut ExtraData ;
632- callback_error_ext ( ( * extra) . raw_lua ( ) . state ( ) , extra, |_| {
632+ callback_error_ext ( ( * extra) . raw_lua ( ) . state ( ) , extra, |extra , _| {
633633 let cb = mlua_expect ! (
634634 ( * extra) . warn_callback. as_ref( ) ,
635635 "no warning callback set in warn_proc"
0 commit comments