How gogdc binds methods in our Go files to entry points that Godot can call through GDNative is controlled by specially formatted comments, in this section we will present all of them including the properties struct fields, this section complements the information available in Class Auto Registration / Overview.
Class auto registration has two forms, passthrough or aliased
check class autoregistration for more details
//godot::register
type MyGoStruct struct{}
//godot::register as Enemy
type MyEnemyGoType struct{}
Go does not have a concept of value constructor or destructor but we can bind any Go functions to our Godot class even if the function is not a method of the registered class
//godot::constructor(MyGoType)
func New() *MyGoType {
gt := MyGoType{}
return >
}
check constructor and destructor for more details
Only annotated (or commented) methods get exported an made available to Godot, methods as classes can be exported as passthrough or aliased
check methods for more details
unexported Go methods are ignored by gogdc and they are not exported into Godot even if they are decorated
//godot::export
func (gt *MyGoType) MyMethod() gdnative.Variant {
return gdnative.NewVariantWithString("Hello Godot!")
}
//godot::export as my_method
func (gt *MyGoType) MyMethod() gdnative.Variant {
return gdnative.NewVariantWithString("Hello Godot!")
}
Properties doesn’t use comment annotations but struct field tags. Note that these tags are not evaluated on runtime as gdnative-go does not uses the reflect at all in runtime.
Properties are registered as they are encountered in the exported classes, struct field tags are used to set options to them, the four tags that can be configured are rset_type
, usage
, hint
and hint_string
each one of them corresponding to their Godot counterparts
all these are case sensitive and must be written in the same camel case
all these are case sensitive and must be written in the same camel case