@@ -434,7 +434,7 @@ impl Function {
434
434
/// [`Compiler::set_coverage_level`]: crate::chunk::Compiler::set_coverage_level
435
435
#[ cfg( any( feature ="luau" , doc) ) ]
436
436
#[ cfg_attr( docsrs, doc( cfg( feature ="luau" ) ) ) ]
437
- pub fn coverage < F > ( & self , mut func : F )
437
+ pub fn coverage < F > ( & self , func : F )
438
438
where
439
439
F : FnMut ( CoverageInfo ) ,
440
440
{
@@ -454,13 +454,16 @@ impl Function {
454
454
} else {
455
455
None
456
456
} ;
457
- let rust_callback =& mut * ( dataas * mut F ) ;
458
- rust_callback ( CoverageInfo {
459
- function,
460
- line_defined,
461
- depth,
462
- hits : slice:: from_raw_parts ( hits, size) . to_vec ( ) ,
463
- } ) ;
457
+ let rust_callback =& * ( dataas * const RefCell < F > ) ;
458
+ if let Ok ( mut rust_callback) = rust_callback. try_borrow_mut ( ) {
459
+ // Call the Rust callback with CoverageInfo
460
+ rust_callback ( CoverageInfo {
461
+ function,
462
+ line_defined,
463
+ depth,
464
+ hits : slice:: from_raw_parts ( hits, size) . to_vec ( ) ,
465
+ } ) ;
466
+ }
464
467
}
465
468
466
469
let lua =self . 0 . lua . lock ( ) ;
@@ -470,7 +473,8 @@ impl Function {
470
473
assert_stack ( state, 1 ) ;
471
474
472
475
lua. push_ref ( & self . 0 ) ;
473
- let func_ptr =& mut funcas * mut F as * mut c_void ;
476
+ let func =RefCell :: new ( func) ;
477
+ let func_ptr =& funcas * const RefCell < F > as * mut c_void ;
474
478
ffi:: lua_getcoverage ( state, -1 , func_ptr, callback :: < F > ) ;
475
479
}
476
480
}