[][src]Macro gdnative::godot_class

macro_rules! godot_class {
    (class $ name : ident ($ user_data : ty) : $ owner : ty
 {
     fields { $ ($ (# [$ fattr : meta]) * $ fname : ident : $ fty : ty,) * }
     setup ($ builder : ident) $ pbody : block constructor
     ($ owner_name : ident : $ owner_ty : ty) $ construct : block $
     ($ tt : tt) *
 }) => { ... };
    (class $ name : ident : $ owner : ty
 {
     fields { $ ($ (# [$ fattr : meta]) * $ fname : ident : $ fty : ty,) * }
     setup ($ builder : ident) $ pbody : block constructor
     ($ owner_name : ident : $ owner_ty : ty) $ 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(_owner: godot::Node) {
           HelloWorld {
               x: 0.0,
           }
       }

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