mirror of
https://github.com/guilhermewerner/reflection
synced 2025-06-15 13:14:19 +00:00
Update macros
This commit is contained in:
@ -18,3 +18,4 @@ members = ["Macros"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
reflection-macros = { path = "Macros" }
|
reflection-macros = { path = "Macros" }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
paste = "1.0.6"
|
||||||
|
@ -4,21 +4,41 @@
|
|||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, DeriveInput};
|
use syn::{parse_macro_input, DeriveInput, ItemFn};
|
||||||
|
|
||||||
#[proc_macro_derive(Reflect, attributes(property))]
|
#[proc_macro_derive(Reflect, attributes(property))]
|
||||||
pub fn reflect(input: TokenStream) -> TokenStream {
|
pub fn reflect(input: TokenStream) -> TokenStream {
|
||||||
let ast = parse_macro_input!(input as DeriveInput);
|
let class = parse_macro_input!(input as DeriveInput);
|
||||||
let name = &ast.ident;
|
let name = &class.ident;
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
impl Reflect for #name {}
|
unsafe impl Reflect for #name {
|
||||||
|
fn TypeName(&self) -> &'static str {
|
||||||
|
std::any::type_name::<Self>()
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expanded.into()
|
expanded.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn function(attr: TokenStream, item: TokenStream) -> TokenStream {
|
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()
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,18 @@ pub struct Foo {
|
|||||||
#[property(visible, editable, category = "Default")]
|
#[property(visible, editable, category = "Default")]
|
||||||
pub a: u32,
|
pub a: u32,
|
||||||
|
|
||||||
#[property(visible, editable, category = "Default")]
|
#[property(visible, editable, readwrite, category = "Default")]
|
||||||
pub b: Bar,
|
pub b: Bar,
|
||||||
|
|
||||||
#[property(visible, editable, category = "Default")]
|
#[property(visible, readonly, category = "Default")]
|
||||||
pub c: Vec<u128>,
|
pub c: Vec<u128>,
|
||||||
|
|
||||||
#[property(visible, editable, category = "Default")]
|
#[property(hidden)]
|
||||||
pub d: Vec<Bar>,
|
pub d: Vec<Bar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Foo {
|
impl Foo {
|
||||||
#[function(callable, category = "Default")]
|
#[function(callable, multicast, category = "Default")]
|
||||||
pub fn Func(&mut self) {}
|
pub fn Func(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +27,6 @@ pub struct Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Bar {
|
impl Bar {
|
||||||
#[function(callable, category = "Default")]
|
#[function(event, server, reliable, category = "Default")]
|
||||||
pub fn Func(&mut self) {}
|
pub fn Func(&mut self) {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user