Macros & APIs

Back to Scripts

Common macros and runtime helpers used by scripts. Most macros take short closures so runtime borrows end at closure exit instead of leaking across large blocks.

Signature Index

// node / scenecreate_node!(ctx, NodeType, name?, tags?, parent?) -> NodeIDwith_node!(ctx, NodeType, node_id, |node| -> V { ... }) -> Vwith_node_mut!(ctx, NodeType, node_id, |node| -> V { ... }) -> Option<V>with_base_node!(ctx, BaseType, node_id, |node| -> V { ... }) -> Vwith_base_node_mut!(ctx, BaseType, node_id, |node| -> V { ... }) -> Option<V>reparent!(ctx, node_id, new_parent_id) -> ()remove_node!(ctx, node_id) -> () // state / scriptwith_state!(ctx, StateType, node_id, |state| -> V { ... }) -> Vwith_state_mut!(ctx, StateType, node_id, |state| -> V { ... }) -> Option<V>get_var!(ctx, node_id, member) -> Variantset_var!(ctx, node_id, member, value) -> ()call_method!(ctx, node_id, method, params) -> Variant

Node / Scene

  • create_node!(ctx, Type, name?, tags?, parent?)
  • with_node! returns data; with_node_mut! mutates data
  • with_node_mut! returns Option<V>, so mutation closures can return computed values
  • closure return types keep read/mutate operations explicit
  • reparent! / remove_node!

State & Scripts

  • with_state! / with_state_mut!
  • with_state_mut! returns Option<V> from closure return value
  • get_var! / set_var!
  • call_method! / method!("name")
  • use params![...] + variant!(...) for dynamic boundary values

Macro Pages by Subsystem

Example

// create nodelet id = create_node!(ctx, Node2D, "MyNode", ["tag"], parent_id); // state accesswith_state_mut!(ctx, PlayerState, id, |s| s.health -= 1); // node read returns datalet texture = with_node!(ctx, Sprite2D, id, |node| node.texture);let transform = with_node!(ctx, Sprite2D, id, |node| (node.position, node.visible)); // node mutatewith_node_mut!(ctx, Sprite2D, id, |node| node.texture = texture); // call method dynamicallycall_method!(ctx, id, method!("tick"), params![42]);