JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

no clue what this is

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨7889bf6

⁨giterated-plugin/giterated-macros/src/lib.rs⁩ - ⁨2060⁩ bytes
Raw
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!("runtime vtable insertion is not implemented")
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 unsafe extern "C" fn plugin_name() -> ::giterated_plugin::abi::FfiSliceRef<str> {
42 ::giterated_plugin::abi::FfiSliceRef::static_ref("plugin name")
43 }
44
45 unsafe extern "C" fn plugin_version() -> ::giterated_plugin::abi::FfiSliceRef<str> {
46 ::giterated_plugin::abi::FfiSliceRef::static_ref("0.0.1")
47 }
48
49 unsafe extern "C" fn type_metadata() -> ::giterated_plugin::abi::value_ex::FfiValueRefUntyped {
50 todo!()
51 }
52
53 static PLUGIN_VTABLE: ::giterated_plugin::abi::vtable::plugin::PluginVTable = ::giterated_plugin::abi::vtable::plugin::PluginVTable {
54 plugin_name,
55 plugin_version,
56 type_metadata
57 };
58
59 ::giterated_plugin::abi::vtable::VTable::new(&PLUGIN_VTABLE)
60 }
61 }
62 }
63