Skip to content

How to export enums from Go to Godot? #32

Answered by Splizard
ShirenY asked this question in Q&A
Discussion options

You must be logged in to vote
package main

import "grow.graphics/gd"
import "grow.graphics/gd/gdextension"

type MyEnum int

const (
    Value1 MyEnum = iota
    Value2
)

type MyClassWithConstants struct {
	gd.Class[MyClassWithConstants, gd.Node2D]
}

func (*MyClassWithConstants) OnRegister(godot gd.Context) {
	godot.Register(gd.Enum[MyClassWithConstants, MyEnum]{
		Name: "MyEnum",
		Values: map[string]MyEnum{
			"Value1": Value1,
			"Value2": Value2,
		},
	})
}

func main() {
    godot, ok := gdextension.Link()
    if ok {
        gd.Register[MyClassWithConstants](godot)
    }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ShirenY
Comment options

@Splizard
Comment options

@ShirenY
Comment options

Answer selected by Splizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants