Abandoning Swift Bindings for Godot
Jun 20, 2020After putting about two weeks of effort into creating Swift bindings for the Godot engine, I’ve decided to abandon the idea. Here’s what I got working:
- Use
api.json
to generate Swifty wrappers around Godot’s classes - Register custom classes that extend a Godot class (godot-cpp does this) or have a Godot instance as an attachment (godot-rust does this)
- Register methods associated with these custom classes
- Callbacks and virtual functions work (
_ready
,_process
etc.) - Singletons work (
Engine
,Input
etc.)
However, Swift’s support for metaprogramming is terrible. Reflection is poorly supported (properties only) and there’s no support for macros or anything else that lets you create a metaprogram. Generics are severely crippled (cannot store constrained generics inside variables, cannot use Unmanaged
with protocols), closures are extremely restrictive (same problem with constrained generics). All of this to say that there is no way to create convenient wrappers that would let users of my bindings register their own classes and methods without mucking about with Godot’s native API to specify their own constructors, destructors and methods to write to and read from user_data
.
I wish Jonathan Blow would go ahead and release Jai into open beta, but in the meantime I plan to give godot-rust a shot.