diff --git a/Cargo.toml b/Cargo.toml index f6a0c62..004e1b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ members = ["Macros"] [dependencies] reflection-macros = { path = "Macros" } anyhow = "1.0" +paste = "1.0.6" diff --git a/Macros/lib.rs b/Macros/lib.rs index 0f9afa4..a4a9090 100644 --- a/Macros/lib.rs +++ b/Macros/lib.rs @@ -4,21 +4,41 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, DeriveInput}; +use syn::{parse_macro_input, DeriveInput, ItemFn}; #[proc_macro_derive(Reflect, attributes(property))] pub fn reflect(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - let name = &ast.ident; + let class = parse_macro_input!(input as DeriveInput); + let name = &class.ident; let expanded = quote! { - impl Reflect for #name {} + unsafe impl Reflect for #name { + fn TypeName(&self) -> &'static str { + std::any::type_name::() + } + } }; expanded.into() } +#[doc(hidden)] #[proc_macro_attribute] pub fn function(attr: TokenStream, item: TokenStream) -> TokenStream { - item + let func = parse_macro_input!(item as ItemFn); + let name = &func.sig.ident; + + let expanded = quote! { + #func + + paste::paste! { + #[doc(hidden)] + pub fn [<__ #name _Client>]() {} + + #[doc(hidden)] + pub fn [<__ #name _Server>]() {} + } + }; + + expanded.into() } diff --git a/Source/Examples/mod.rs b/Source/Examples/mod.rs index 4c165b5..b122b1f 100644 --- a/Source/Examples/mod.rs +++ b/Source/Examples/mod.rs @@ -5,18 +5,18 @@ pub struct Foo { #[property(visible, editable, category = "Default")] pub a: u32, - #[property(visible, editable, category = "Default")] + #[property(visible, editable, readwrite, category = "Default")] pub b: Bar, - #[property(visible, editable, category = "Default")] + #[property(visible, readonly, category = "Default")] pub c: Vec, - #[property(visible, editable, category = "Default")] + #[property(hidden)] pub d: Vec, } impl Foo { - #[function(callable, category = "Default")] + #[function(callable, multicast, category = "Default")] pub fn Func(&mut self) {} } @@ -27,6 +27,6 @@ pub struct Bar { } impl Bar { - #[function(callable, category = "Default")] + #[function(event, server, reliable, category = "Default")] pub fn Func(&mut self) {} }