class!() { /* proc-macro */ }
Expand description
An easy way to be able to define a Node.
§Example
ⓘ
use node_tree::prelude::*;
class! {
/// Documentation and attributes are supported!
pub dec NodeName;
/// A signal can be connected to node functions and emitted.
/// Safety is guaranteed via the scene tree.
pub sig on_event(param_name: Type, ..);
/// Constants are supported.
const SOME_CONST: &str = "Hello";
/// Fields can be defined like so, with default or without default values.
let field_uninit: u8;
let field_initialized: String = "These are not constant expressions!".to_string();
// Fields can have special attributes, like so:
default let field_default: u8; // Will automatically initialzie to zero.
unique let field_unique: *mut c_void; // When cloned or serialized, this will safetly be initialized as a `None` value.
// Exportable fields will be saved and loaded from whenever a node scene is serialized.
// Note: All exported types will need to implement the `Exportable` trait.
export let some_parameter: String;
export default let some_parameter_default: bool;
// Hooks are any system functions that can be overridden.
// This include the constructor `_init()`, `loaded()`, `ready()`, `process()`, `terminal()`, and `process_mode()`.
/// The constructor may only need to be implemented if there exists fields that do not have
/// a default value.
/// Note that this macro will automatically create a `new()` invokation, even without a
/// predefined `_init()` hook. All attributes given to this hook will be transferred to the
/// `new()` function.
hk _init(starter_value: u8) {
// Initialize a value by creating a variable with the same field name:
let field_uninit: u8 = starter_value;
}
/// Functions can be declared as per usual.
fn foo(bar: Type) -> Type {
todo!();
}
}