Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
3 tasks
* feat: Support Swift functions in `SwiftConverter<T>` * remoev * fix cxx * fix: Generate old code again to keep it working * only generate (Double) -> Void for now. * ok it builds * ok that now works! * holy shit it runs * make it static
* feat: Implement `SwiftConverter<T>` for structs * Add all imports * use param for escaping * generate a whole bunch of funcs * fix: Fix weird func names * no name info in converter * don't do any result bridging for now * remove a lot of c++ bridges * move `call` to impl * remove a lot more * fix: Add back functions for Promise (resolver/rejecter) * Rewrite `AnyMap` to use Swift implementation...? * fix HybridObject downcast * Ok create `SwiftAnyMap` wrapper again * Import `SwiftAnyMap` * Handle array * Move Swift calls from .hpp into .cpp * Swift part can be `std::shared_ptr` to avoid including it * fix some
5baca6e to
a288e65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Concept
The idea is simple; currently we pass C++ STL types directly to Swift (
std::string->std.string), and also convert them inside Swift - currently this looks like this;Swift:
C++:
To allow for extending external types, I had the idea to convert C++ STL types to Swift types while we're still in C++ land, so this will look like this:
Swift:
C++:
Implementation
As already hinted by the code above, this introduces a new template class:
SwiftConverter<T>.This
SwiftConverter<T>allows to convert any C++ STL type to a Swift type and back using the Swift <> C++ interop.This is quite tricky now, since the Swift types (
swift::String,swift::Optional<T>,swift::Array<T>, ...) are generated per module (so each Pod/Framework has it's own definition ofswift::String, even though they are identical).I first tried to simply forward declare it, and only
NitroModulesmodule/Pod defines it inside it's.cppfile so that we don't need to define those templates multiple times - but this only works for fixed types likeswift::String, and not for templated types likeswift::Optional<T>orswift::Array<T>, since those have to be known at the time when I define the interface/hpp file.So now it all lives inside the .hpp file.
Progress
Currently I have implemented
SwiftConverter<T>fordouble,std::string,std::optional<T>andstd::vector<T>.I am now stuck at
std::function<...>since that requires hybrid state- one implementation has to live in Swift, one in C++, and I cannot define it just once because Swift does not have variadic generics (or at least only after iOS 17, and C++ cannot interop with that yet).I am not sure how to implement that properly tbh.