File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " objc-foundation-derive"
3
+ version = " 0.0.0"
4
+ authors = [" Steven Sheldon" ]
5
+
6
+ [lib ]
7
+ proc-macro = true
8
+
9
+ [dependencies ]
10
+ syn = " 0.10.5"
11
+ quote = " 0.3.10"
Original file line number Diff line number Diff line change
1
+ #![ feature( proc_macro, proc_macro_lib) ]
2
+
3
+ extern crate proc_macro;
4
+ extern crate syn;
5
+ #[ macro_use]
6
+ extern crate quote;
7
+
8
+ use proc_macro:: TokenStream ;
9
+
10
+ #[ proc_macro_derive( INSObject ) ]
11
+ pub fn impl_object ( input : TokenStream ) -> TokenStream {
12
+ // Construct a string representation of the type definition
13
+ let s = input. to_string ( ) ;
14
+
15
+ // Parse the string representation
16
+ let ast = syn:: parse_macro_input ( & s) . unwrap ( ) ;
17
+
18
+ // Build the impl
19
+ let name = & ast. ident ;
20
+ let gen = quote ! {
21
+ unsafe impl :: objc:: Message for #name { }
22
+
23
+ impl :: objc_foundation:: INSObject for #name {
24
+ fn class( ) -> & ' static :: objc:: runtime:: Class {
25
+ let name = stringify!( #name) ;
26
+ match :: objc:: runtime:: Class :: get( name) {
27
+ Some ( cls) => cls,
28
+ None => panic!( "Class {} not found" , name) ,
29
+ }
30
+ }
31
+ }
32
+ } ;
33
+
34
+ // Return the generated impl
35
+ gen. parse ( ) . unwrap ( )
36
+ }
You can’t perform that action at this time.
0 commit comments