[][src]Macro gdnative_core::godot_class

macro_rules! godot_class {
    (
class $name:ident: $owner:ty {
    fields {
        $(
            $(#[$fattr:meta])*
            $fname:ident : $fty:ty,
        )*
    }
    setup($builder:ident) $pbody:block
    constructor($header:ident) $construct:block

    $($tt:tt)*
}
    ) => { ... };
}

Convenience macro to declare a native class.

Example

This example is not tested
godot_class! {
   class HelloWorld: godot::Node {
       fields {
           x: f32,
       }

       setup(builder) {
           builder.add_property(
               Property {
                   name: "base/x",
                   default: 1.0,
                   hint: PropertyHint::Range {
                       range: 0.0..1.0,
                       step: 0.01,
                       slider: true
                   },
                   getter: |this: &mut RustTest| this.x,
                   setter: |this: &mut RustTest, v| this.x = v,
                   usage: PropertyUsage::DEFAULT,
               }
           );
       }

       constructor(header) {
           HelloWorld {
               header,
           }
       }

       export fn _ready(&mut self) {
           godot_print!("hello, world.");
       }
   }
}