File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -872,6 +872,49 @@ fn test_application_data() -> Result<()> {
872872 Ok ( ( ) )
873873}
874874
875+ #[ test]
876+ fn test_rust_function ( ) -> Result < ( ) > {
877+ let lua = Lua :: new ( ) ;
878+
879+ let globals = lua. globals ( ) ;
880+ lua. load (
881+ r#"
882+ function lua_function()
883+ return rust_function()
884+ end
885+
886+ -- Test to make sure chunk return is ignored
887+ return 1
888+ "# ,
889+ )
890+ . exec ( ) ?;
891+
892+ let lua_function = globals. get :: < Function > ( "lua_function" ) ?;
893+ let rust_function = lua. create_function ( |_, ( ) | Ok ( "hello" ) ) ?;
894+
895+ globals. set ( "rust_function" , rust_function) ?;
896+ assert_eq ! ( lua_function. call:: <String >( ( ) ) ?, "hello" ) ;
897+
898+ Ok ( ( ) )
899+ }
900+
901+ #[ test]
902+ fn test_c_function ( ) -> Result < ( ) > {
903+ let lua = Lua :: new ( ) ;
904+
905+ unsafe extern "C-unwind" fn c_function ( state : * mut mlua:: lua_State ) -> std:: os:: raw:: c_int {
906+ ffi:: lua_pushboolean ( state, 1 ) ;
907+ ffi:: lua_setglobal ( state, b"c_function\0 " as * const _ as * const _ ) ;
908+ 0
909+ }
910+
911+ let func = unsafe { lua. create_c_function ( c_function) ? } ;
912+ func. call :: < ( ) > ( ( ) ) ?;
913+ assert_eq ! ( lua. globals( ) . get:: <bool >( "c_function" ) ?, true ) ;
914+
915+ Ok ( ( ) )
916+ }
917+
875918#[ test]
876919#[ cfg( not( target_arch = "wasm32" ) ) ]
877920fn test_recursion ( ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments