mirror of
https://github.com/bevyengine/bevy
synced 2024-12-23 19:43:07 +00:00
20 lines
674 B
Rust
20 lines
674 B
Rust
|
use quote::quote;
|
||
|
use syn::{parse_macro_input, DeriveInput};
|
||
|
use proc_macro::TokenStream;
|
||
|
|
||
|
pub fn derive_app_plugin(input: TokenStream) -> TokenStream {
|
||
|
let ast = parse_macro_input!(input as DeriveInput);
|
||
|
let struct_name = &ast.ident;
|
||
|
|
||
|
TokenStream::from(quote! {
|
||
|
#[no_mangle]
|
||
|
pub extern "C" fn _create_plugin() -> *mut bevy::app::AppPlugin {
|
||
|
// TODO: without this the assembly does nothing. why is that the case?
|
||
|
print!("");
|
||
|
// make sure the constructor is the correct type.
|
||
|
let object = #struct_name {};
|
||
|
let boxed = Box::new(object);
|
||
|
Box::into_raw(boxed)
|
||
|
}
|
||
|
})
|
||
|
}
|