Skip to content

Support enums in arrays, with correct export hints #353

@gg-yb

Description

@gg-yb

The relevant type string hint is generated here:

format!("{}:{}", sys::VariantType::Array as i32, T::type_string())

Example code:

...
pub struct Textbox {
  ...
  #[export]
  font_types: Array<FontType>,
  ...
}
...

vs.

extends Control

enum Foo {
	Bar = 0,
	Baz = 1,
	Qux = 2,
}

@export
var lol: Array[Foo] = []

When inspected via

func _ready():
	for prop in get_property_list():
		if prop.name == "lol":
			print(prop)
	var mt = Textbox.new()
	for prop in mt.get_property_list():
		if prop.name == "font_types":
			print(prop)

the following output is obtained:

{ "name": "lol", "class_name": &"", "type": 28, "hint": 23, "hint_string": "2/2:Bar:0,Baz:1,Qux:2", "usage": 4102 }
{ "name": "font_types", "class_name": &"Textbox", "type": 28, "hint": 23, "hint_string": "Generic33x8:0,Greek33x3:1,Cyrillic33x4:2,Compact6x6:3", "usage": 6 }

Note the missing "2/2:" prefix. After some digging around, the first 2 apparently stands for VariantType::Int, the second 2 stands for PROPERTY_HINT_ENUM, though I am not 100% sure of this.

Note that the gdext version does not work in the editor, it simply shows up as unspecified ints, while the gdscript variant shows the enum labels.

Note that I implement TypeStringHint for FontType with what is essentially the "hint_string" from the output. From my understanding, there should still be a prefix added to the hint from the line referenced above, but it appears to not be added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions