@@ -27,6 +27,35 @@ impl CppFn {
2727 self . type_name ( ) . write ( config, & [ ] )
2828 }
2929
30+ pub fn write_fn_ptr ( & self , config : & Config < ' _ > , underlying_types : bool ) -> TokenStream {
31+ let ptr_name = self . method . name ( ) . to_string ( ) + "Fn" ;
32+ let name = to_ident ( & ptr_name) ;
33+ let abi = self . method . calling_convention ( ) ;
34+ let signature = self . method . signature ( self . namespace , & [ ] ) ;
35+
36+ let params = signature. params . iter ( ) . map ( |param| {
37+ let name = param. write_ident ( ) ;
38+ let ty = if underlying_types {
39+ param. underlying_type ( ) . write_abi ( config)
40+ } else {
41+ param. write_abi ( config)
42+ } ;
43+ quote ! { #name: #ty }
44+ } ) ;
45+
46+ let return_sig = config. write_return_sig ( self . method , & signature, underlying_types) ;
47+
48+ let vararg = if config. sys && signature. call_flags . contains ( MethodCallAttributes :: VARARG ) {
49+ quote ! { , ... }
50+ } else {
51+ quote ! { }
52+ } ;
53+
54+ link_fmt ( quote ! {
55+ pub type #name = unsafe extern #abi fn ( #( #params) , * #vararg) #return_sig;
56+ } )
57+ }
58+
3059 pub fn write_link ( & self , config : & Config < ' _ > , underlying_types : bool ) -> TokenStream {
3160 let library = self . method . module_name ( ) . to_lowercase ( ) ;
3261 let symbol = self . method . import_name ( ) ;
@@ -71,6 +100,7 @@ impl CppFn {
71100 let name = to_ident ( self . method . name ( ) ) ;
72101 let signature = self . method . signature ( self . namespace , & [ ] ) ;
73102
103+ let ptr = self . write_fn_ptr ( config, false ) ;
74104 let link = self . write_link ( config, false ) ;
75105 let arches = write_arches ( self . method ) ;
76106 let cfg = self . write_cfg ( config) ;
@@ -79,6 +109,9 @@ impl CppFn {
79109
80110 if config. sys {
81111 return quote ! {
112+ #cfg
113+ #ptr
114+ #window_long
82115 #cfg
83116 #link
84117 #window_long
0 commit comments