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

ambee/giterated

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

Fucking whatever there you go

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨57c2ca5

⁨plugins/example-plugin/src/lib.rs⁩ - ⁨2479⁩ bytes
Raw
1 use std::sync::OnceLock;
2
3 use giterated_models::{
4 error::OperationError,
5 instance::Instance,
6 object::ObjectRequest,
7 user::{DisplayName, User},
8 };
9 use giterated_plugin::{
10 handle::PluginInitializationState,
11 new_stack::{FFIPluginMeta, PluginState},
12 vtable::{HostVTable, InitializationVTable},
13 };
14 use giterated_plugin_sys::PluginStackBuilder;
15 use tracing::{info, trace_span, Level};
16
17 static INIT_VTABLE: OnceLock<InitializationVTable> = OnceLock::new();
18
19 #[no_mangle]
20 pub extern "C" fn plugin_meta() -> FFIPluginMeta {
21 const PLUGIN_NAME: &str = "Example Plugin";
22 const PLUGIN_VERSION: &str = "1.0.0";
23
24 FFIPluginMeta {
25 name: PLUGIN_NAME.as_ptr(),
26 name_len: PLUGIN_NAME.len(),
27 version: PLUGIN_VERSION.as_ptr(),
28 version_len: PLUGIN_VERSION.len(),
29 }
30 }
31
32 #[no_mangle]
33 pub extern "C" fn load_host_vtable(_vtable: &HostVTable) {
34 println!("Loading vtable");
35 }
36
37 #[no_mangle]
38 pub extern "C" fn load_initialization_vtable(init_vtable: &InitializationVTable) {
39 INIT_VTABLE.set(init_vtable.clone()).unwrap();
40 println!("Loaded initialization vtable");
41 }
42
43 #[no_mangle]
44 pub extern "C" fn initialize() -> PluginState {
45 tracing_subscriber::fmt()
46 .pretty()
47 .with_thread_names(true)
48 .with_max_level(Level::TRACE)
49 .init();
50
51 PluginState {
52 inner: Box::into_raw(Box::new(())),
53 }
54 }
55
56 #[no_mangle]
57 pub extern "C" fn initialize_registration(
58 state: *mut PluginInitializationState,
59 ) -> *mut PluginInitializationState {
60 let _guard: tracing::span::EnteredSpan = trace_span!("initialize_registration").entered();
61 let init_vtable = INIT_VTABLE.get().unwrap();
62 let mut builder = PluginStackBuilder::new((), state, init_vtable);
63
64 builder.object::<Instance>().object::<User>();
65 builder.operation(handler);
66 builder.value(value_getter);
67 // builder.setting_getter(setting_getter);
68
69 state
70 }
71
72 async fn handler(
73 state: (),
74 _object: Instance,
75 _operation: ObjectRequest,
76 ) -> Result<(), OperationError<()>> {
77 info!("handling operation!");
78
79 todo!()
80 }
81
82 async fn value_getter(
83 state: (),
84 object: User,
85 ) -> Result<DisplayName, OperationError<anyhow::Error>> {
86 info!("OwO, value gotten!");
87
88 Ok(DisplayName(String::from("heya!")))
89 }
90
91 // fn setting_getter(state: (), object: User) -> Result<DisplayName, ()> {
92 // info!("OwO, setting gotten!");
93
94 // Ok(DisplayName(String::from("heya! (but from a setting)")))
95 // }
96