Skip to main content

rusteal_macros/
lib.rs

1// rusteal-macros: proc macros for #[uclass], #[ufunction], #[uproperty].
2
3mod prop_type;
4mod uclass;
5mod uclass_impl;
6
7/// Attribute macro for defining a Rust struct as a UE class.
8///
9/// # Example
10/// ```ignore
11/// #[uclass(parent = Actor)]
12/// pub struct MyEnemy {
13///     #[uproperty(BlueprintReadWrite, default = 100.0)]
14///     health: f32,
15///
16///     // Rust-private field (no #[uproperty])
17///     chase_timer: f64,
18/// }
19/// ```
20#[proc_macro_attribute]
21pub fn uclass(
22    attr: proc_macro::TokenStream,
23    item: proc_macro::TokenStream,
24) -> proc_macro::TokenStream {
25    match uclass::expand_uclass(attr.into(), item.into()) {
26        Ok(tokens) => tokens.into(),
27        Err(err) => err.to_compile_error().into(),
28    }
29}
30
31/// Attribute macro for an impl block on a `#[uclass]` struct.
32/// Methods marked `#[ufunction(...)]` become UE-callable functions.
33///
34/// # Example
35/// ```ignore
36/// #[uclass_impl]
37/// impl MyEnemy {
38///     #[ufunction(BlueprintCallable)]
39///     fn take_damage(&mut self, amount: f32) -> bool {
40///         let h = self.health() - amount;
41///         self.set_health(h.max(0.0));
42///         h <= 0.0
43///     }
44///
45///     fn helper(&self) -> f32 { self.health() * 2.0 }  // plain Rust method
46/// }
47/// ```
48#[proc_macro_attribute]
49pub fn uclass_impl(
50    attr: proc_macro::TokenStream,
51    item: proc_macro::TokenStream,
52) -> proc_macro::TokenStream {
53    match uclass_impl::expand_uclass_impl(attr.into(), item.into()) {
54        Ok(tokens) => tokens.into(),
55        Err(err) => err.to_compile_error().into(),
56    }
57}