AdaEngine / box2d-swift

The box2d bridging to Swift
3 stars 0 forks source link

'import_as_ref' macro attribute makes initializer inaccessible in Swift #1

Closed igorkravchenko closed 2 months ago

igorkravchenko commented 3 months ago

Hi! First of all thanks for this great Swift/C++ interoperability example.

It seems that right now there's no way to create instance of b2World (and other C++ classes) in Swift. Most likely this is related to import_as_ref attribute. If this attribute is omitted, then b2World.init(_ gravity: b2Vec2) gets synthesized, but b2World is no longer a class but struct. Is there a way to enforce initializer synthesis for C++ classes while still keeping them as reference?

SpectralDragon commented 3 months ago

Hi! Sorry for late answer. It seems like we should try to remove AS_SWIFT_CLASS macro and try to use default C++ interop. I used that macro a long time ago, when C++ interop was in experimental mode, maybe in Swift 5.9 all troubles was resolved, but I 'm not sure about it...

SpectralDragon commented 2 months ago

@igorkravchenko Hi!

I have updated box2d and now it full compatible to use in Swift project.

You can check it here: AdaEngine PhysicsWorld2D.swift

If you have any question, please reopen issue.