11use std:: cell:: RefCell ;
22use std:: ops:: Deref ;
3- use std:: str;
43use std:: sync:: { Arc , Mutex } ;
54
6- use rlua:: { Error , HookTriggers , Lua , Value } ;
5+ use rlua:: { Error , HookTriggers , Lua , Value , RluaCompat } ;
76
87#[ cfg( not( rlua_luajit) ) ] // LuaJIT gives different results
98#[ test]
@@ -52,8 +51,8 @@ fn function_calls() {
5251 move |_lua, debug| {
5352 let names = debug. names ( ) ;
5453 let source = debug. source ( ) ;
55- let name = names. name . map ( |s| str :: from_utf8 ( s ) . unwrap ( ) . to_owned ( ) ) ;
56- let what = source. what . map ( |s| str :: from_utf8 ( s ) . unwrap ( ) . to_owned ( ) ) ;
54+ let name = names. name . map ( |s| s . to_string ( ) ) ;
55+ let what = source. what ;
5756 hook_output. lock ( ) . unwrap ( ) . push ( ( name, what) ) ;
5857 Ok ( ( ) )
5958 } ,
@@ -73,8 +72,8 @@ fn function_calls() {
7372 assert_eq ! (
7473 * output,
7574 vec![
76- ( None , Some ( "main" . to_string ( ) ) ) ,
77- ( Some ( "len" . to_string( ) ) , Some ( "C" . to_string ( ) ) )
75+ ( None , "main" ) ,
76+ ( Some ( "len" . to_string( ) ) , "C" )
7877 ]
7978 ) ;
8079 #[ cfg( rlua_luajit) ]
@@ -119,16 +118,18 @@ fn error_within_hook() {
119118#[ test]
120119fn limit_execution_instructions ( ) {
121120 let lua = Lua :: new ( ) ;
122- let mut max_instructions = 10000 ;
121+ let max_instructions = Arc :: new ( Mutex :: new ( 10000 ) ) ;
122+ let max_int = Arc :: clone ( & max_instructions) ;
123123
124124 lua. set_hook (
125125 HookTriggers {
126126 every_nth_instruction : Some ( 30 ) ,
127127 ..Default :: default ( )
128128 } ,
129129 move |_lua, _debug| {
130- max_instructions -= 30 ;
131- if max_instructions < 0 {
130+ let mut max_instructions = max_int. lock ( ) . unwrap ( ) ;
131+ ( * max_instructions) -= 30 ;
132+ if ( * max_instructions) < 0 {
132133 Err ( Error :: RuntimeError ( "time's up" . to_string ( ) ) )
133134 } else {
134135 Ok ( ( ) )
0 commit comments