From cb0ceca6739ab07351a8e452576c35d3b4ed50cc Mon Sep 17 00:00:00 2001 From: Werner <26710260+GuilhermeWerner@users.noreply.github.com> Date: Thu, 23 Dec 2021 12:02:36 -0300 Subject: [PATCH] Update macros --- Cargo.toml | 1 + Macros/lib.rs | 30 +++++++++++++++++++++++++----- Source/Examples/mod.rs | 10 +++++----- 3 files changed, 31 insertions(+), 10 deletions(-) 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::<Self>() + } + } }; 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<u128>, - #[property(visible, editable, category = "Default")] + #[property(hidden)] pub d: Vec<Bar>, } 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) {} }