Before
parent: tbd commit: e432306
1 | plugin! |
2 | name: "Example Plugin", |
3 | version: "0.0.1", |
4 | author: "Amber Kowalski", |
5 | // Experimental syntax for requesting specific plugin features |
6 | features: , |
7 | description: "An example plugin to demonstrate the development process of Giterated plugins." |
8 | ; |
9 | |
10 | /// Some kind of global state for the plugin |
11 | ; |
12 | |
13 | /// The plugin's initialization function. Ran when the plugin is loaded, used to |
14 | /// build the plugin's stack. |
15 | |
16 | |
17 | builder.insert_state; |
18 | |
19 | builder |
20 | . |
21 | .; |
22 | |
23 | builder.value; |
24 | builder.setting_getter; |
25 | |
26 | Ok |
27 | |
28 | |
29 | async |
30 | object: User, |
31 | operation: ObjectRequest, |
32 | state_extractor: |
33 | |
34 | todo! |
35 | |
36 | |
37 | async |
38 | object: User, |
39 | state_extractor: |
40 | |
41 | todo! |
42 | |
43 | |
44 | |
45 | r#" |
46 | static INIT_VTABLE: OnceLock<InitializationVTable> = OnceLock::new(); |
47 | "# |
48 | |
49 | |
50 | |
51 | plugin_name: String, |
52 | plugin_version: String, |
53 | plugin_author: String |
54 | |
55 | |
56 | |
57 | r#" |
58 | const PLUGIN_NAME: &'static str = {constants.plugin_name}; |
59 | const PLUGIN_VERSION: &'static str = {constants.plugin_version}; |
60 | const PLUGIN_AUTHOR: &'static str = {constants.plugin_author}; |
61 | "# |
62 | |
63 | |
64 | // use std::{mem::forget, sync::OnceLock}; |
65 | |
66 | // use giterated_models::{ |
67 | // error::OperationError, |
68 | // instance::Instance, |
69 | // object::{ObjectRequest, ObjectRequestError, ObjectResponse}, |
70 | // user::{DisplayName, User}, |
71 | // }; |
72 | // use giterated_plugin::{ |
73 | // handle::PluginInitializationState, |
74 | // new_stack::{FFIPluginMeta, PluginState}, |
75 | // vtable::{HostVTable}, |
76 | // }; |
77 | // use giterated_plugin_sys::PluginStackBuilder; |
78 | // use tracing::{info, trace_span, Level}; |
79 | |
80 | // static INIT_VTABLE: OnceLock<InitializationVTable> = OnceLock::new(); |
81 | |
82 | // #[no_mangle] |
83 | // pub extern "C" fn plugin_meta() -> FFIPluginMeta { |
84 | // const PLUGIN_NAME: &str = "Example Plugin"; |
85 | // const PLUGIN_VERSION: &str = "1.0.0"; |
86 | |
87 | // FFIPluginMeta { |
88 | // name: PLUGIN_NAME.as_ptr(), |
89 | // name_len: PLUGIN_NAME.len(), |
90 | // version: PLUGIN_VERSION.as_ptr(), |
91 | // version_len: PLUGIN_VERSION.len(), |
92 | // } |
93 | // } |
94 | |
95 | // #[no_mangle] |
96 | // pub extern "C" fn load_host_vtable(_vtable: &HostVTable) { |
97 | // println!("Loading vtable"); |
98 | // } |
99 | |
100 | // #[no_mangle] |
101 | // pub extern "C" fn load_initialization_vtable(init_vtable: &InitializationVTable) { |
102 | // INIT_VTABLE.set(*init_vtable).unwrap(); |
103 | // println!("Loaded initialization vtable"); |
104 | // } |
105 | |
106 | // #[no_mangle] |
107 | // pub extern "C" fn load_type_metadata(metadata: *mut ()) { |
108 | // unsafe { giterated_static_runtime::initialize_type_metadata(metadata) } |
109 | // println!("Initialized type metadata for plugin"); |
110 | // } |
111 | |
112 | // #[no_mangle] |
113 | // pub extern "C" fn initialize() -> PluginState { |
114 | // tracing_subscriber::fmt() |
115 | // .pretty() |
116 | // .with_thread_names(true) |
117 | // .with_max_level(Level::TRACE) |
118 | // .init(); |
119 | |
120 | // println!("Building runtime"); |
121 | // let runtime = tokio::runtime::Builder::new_multi_thread() |
122 | // .enable_all() |
123 | // .build() |
124 | // .unwrap(); |
125 | |
126 | // let _guard = runtime.enter(); |
127 | |
128 | // forget(_guard); |
129 | |
130 | // PluginState { |
131 | // inner: Box::into_raw(Box::new(())), |
132 | // } |
133 | // } |
134 | |
135 | // #[no_mangle] |
136 | // pub extern "C" fn initialize_registration( |
137 | // state: *mut PluginInitializationState, |
138 | // ) -> *mut PluginInitializationState { |
139 | // let _guard: tracing::span::EnteredSpan = trace_span!("initialize_registration").entered(); |
140 | // let init_vtable = INIT_VTABLE.get().unwrap(); |
141 | // let mut builder = PluginStackBuilder::new((), state, init_vtable); |
142 | |
143 | // builder.object::<Instance>().object::<User>(); |
144 | // builder.operation(handler); |
145 | // builder.value(value_getter); |
146 | // builder.setting_getter(setting_getter); |
147 | |
148 | // state |
149 | // } |
150 | |
151 | // async fn handler( |
152 | // _state: (), |
153 | // object: Instance, |
154 | // operation: ObjectRequest, |
155 | // ) -> Result<ObjectResponse, OperationError<ObjectRequestError>> { |
156 | // info!("handling operation!"); |
157 | |
158 | // info!("Try get object {} from instance {}", operation.0, object); |
159 | |
160 | // Ok(ObjectResponse(operation.0)) |
161 | // } |
162 | |
163 | // async fn value_getter( |
164 | // _state: (), |
165 | // _object: User, |
166 | // ) -> Result<DisplayName, OperationError<anyhow::Error>> { |
167 | // info!("OwO, value gotten!"); |
168 | |
169 | // Ok(DisplayName(String::from("heya!"))) |
170 | // } |
171 | |
172 | // async fn setting_getter( |
173 | // _state: (), |
174 | // _object: User, |
175 | // ) -> Result<DisplayName, OperationError<anyhow::Error>> { |
176 | // info!("OwO, setting gotten!"); |
177 | |
178 | // Ok(DisplayName(String::from("heya! (but from a setting)"))) |
179 | // } |
180 |