migueldeicaza / SwiftGodot

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

Declaring swift types from my GDScript classes #472

Closed eimfach closed 6 months ago

eimfach commented 6 months ago

Hello there !

Is it possible to declare types of class members from my own GDScript classes (I use "class_name" there to make it accessible) ? So, basically calling into GDScript ? I didn't find anything that covers that topic...

Thanks

Windows 10 Swift 5.10 Godot 4.2

eimfach commented 6 months ago

So for example I have an enemy controller Node written in GDScript that will get generated pawn nodes as childs (from elsewhere ) also written in GDScript. Now I want to port the enemy controller into Swift...

migueldeicaza commented 6 months ago

Please use the Discussion group for questions, not issues.

You can call the methods using the call method on a given instance, but these are loosely typed, so you do things like:

someObject.call ("method", Variant (1), Variant ("Hello world"), Variant (myVector))

Does that solve the problem?

One thing that I would like to do is to generate bindings of APIs that users define in GDScript or other languages, and there are some other folks interested, I believe it might have been discussed somewhere in Godot land. There is an alternative somewhere in the bug tracking here along the lines of "Run a GDScript to dump the API, and then write a generator for that"

eimfach commented 6 months ago

Hey there, thanks for the reply. I wanted to join the slack server but it doesn't let me.

As for your stated code: I am not sure how I get to that point where I can call "someObject"s methods. "someObject" is a GDScript object I suppose ? If yes, how can I create them ?

migueldeicaza commented 6 months ago

Oh, I mean the discussions here on GitHub:

https://github.com/migueldeicaza/SwiftGodot/discussions