migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.06k stars 65 forks source link

Improve `@Export` to support `Variant` and `GArray` types. #410

Closed EstevanBR closed 5 months ago

EstevanBR commented 5 months ago

If you try to @Export a GArray or a Variant you get this error:

GArray

if let res: GArray = args [0].asObject () {

instance method 'asObject' requires that 'GArray' conform to 'GodotObject'

In this case we'd want GArray(args[0])

Variant

if let res: Variant = args [0].asObject () {

instance method 'asObject' requires that 'Variant' conform to 'GodotObject'

In this case we could just have if let res = args.first (IMO we should be using args.first any place we use args[0])

migueldeicaza commented 5 months ago

Fascinating, in both cases, those are the incorrect casts.

There is no need of the asObject in the Variant case, and for the GArray case we need to call GArray (args[0]) instead.

migueldeicaza commented 5 months ago

Almost have this fixed.