godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
3.12k stars 198 forks source link

Implement (or derive) GodotType for godot compatible repr enums #580

Open jrockett6 opened 9 months ago

jrockett6 commented 9 months ago

I have an enum

#[repr(i32)]
enum RockType {
    Tin = 1,
    Copper = 2,
}

and I would like to be able to

    #[export]
    rock_types: Array<RockType>,

but Array can only hold a GodotType.

Storing an Array<i32> is ok, but we don't have the enum names in the editor and recreating the enum back in rust requires some extra steps.

Would be solved by #334, but posting this as I think this problem much less complex.

lilizoey commented 9 months ago

I dont think the right solution would be to allow user-defined GodotType, rather we should decide on what types can be stored in arrays. For instance we could allow all GodotConvert + ToGodot + FromGodot types, or maybe add a Arrayable trait for things that can go in arrays. or something else.

Bromeon commented 9 months ago

If we want to do this properly, we need Arrayable (named ArrayElem maybe), because not every GodotType can be stored inside arrays.

For example, Array<Array<i32>> is not exportable, because the Godot runtime only stores type information about the outer array type.