Module godotmacros

Search:
Group by:

Macros

macro gdobj(definition: untyped; body: typed): typed {.
immediate
.}
Generates Godot type. Self-documenting example:
import godot, node

gdobj MyObj of Node:
  var myField: int
    ## Not exported to Godot (i.e. editor will not see this field).
  
  var myString* {.gdExport, hint: Length, hintStr: "20".}: string
    ## Exported to Godot as ``my_string``.
    ## Editor will limit this string to length 20.
    ## ``hint` is a value of ``GodotPropertyHint`` enum.
    ## ``hintStr`` depends on the value of ``hint``, its format is
    ## described in ``GodotPropertyHint`` documentation.
  
  method ready*() =
    ## Exported methods are exported to Godot by default,
    ## and their Godot names are prefixed with ``_``
    ## (in this case ``_ready``)
    print("I am ready! myString is: " & myString)
  
  proc myProc*() {.gdExport.} =
    ## Exported to Godot as ``my_proc``
    print("myProc is called! Incrementing myField.")
    inc myField

If parent type is omitted, the type is inherited from Object.

tool specifier can be added to mark the type as an editor plugin:

import godot, editor_plugin

gdobj(MyTool of EditorPlugin, tool):
  method enterTree*() =
    print("MyTool initialized!")

Objects can be instantiated by invoking gdnew or by using load or any other way that you can find in Godot API.

  Source Edit