1 |
use proc_macro::TokenStream;
|
2 |
use quote::quote;
|
3 |
use syn::{parse_macro_input, ItemFn};
|
4 |
|
5 |
extern crate proc_macro;
|
6 |
|
7 |
#[proc_macro]
|
8 |
pub fn plugin(metadata: TokenStream) -> TokenStream {
|
9 |
emit_plugin_api().into()
|
10 |
}
|
11 |
|
12 |
#[proc_macro_attribute]
|
13 |
pub fn plugin_init(attribute: TokenStream, item: TokenStream) -> TokenStream {
|
14 |
let input = parse_macro_input!(item as ItemFn);
|
15 |
|
16 |
let func = input.sig.ident.clone();
|
17 |
|
18 |
quote! {
|
19 |
#[doc(hidden)]
|
20 |
#[no_mangle]
|
21 |
unsafe extern "C" fn __plugin_init() {
|
22 |
#func(&mut ::giterated_plugin::local::PluginStackBuilder::new()).unwrap()
|
23 |
}
|
24 |
|
25 |
#input
|
26 |
}
|
27 |
.into()
|
28 |
}
|
29 |
|
30 |
fn emit_plugin_api() -> impl Into<TokenStream> {
|
31 |
quote! {
|
32 |
#[doc(hidden)]
|
33 |
#[no_mangle]
|
34 |
unsafe extern "C" fn __load_runtime_vtable(vtable: &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::runtime::RuntimeHandle>) {
|
35 |
todo!()
|
36 |
}
|
37 |
|
38 |
#[doc(hidden)]
|
39 |
#[no_mangle]
|
40 |
unsafe extern "C" fn __get_plugin_vtable() -> &'static ::giterated_plugin::abi::vtable::VTable<::giterated_plugin::abi::vtable::plugin::Plugin> {
|
41 |
todo!()
|
42 |
}
|
43 |
}
|
44 |
}
|
45 |
|