-
Notifications
You must be signed in to change notification settings - Fork 8
Delegates on kotlin #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@gabriel-kozma That's correct. Delegates are currently not implemented in the Kotlin code generator. JNA does support mapping C function pointers though so should at least be possible to add. |
sounds good, so the best course of action, would be for me to manually map them? |
@gabriel-kozma Well, best would be to implement Delegates in the Kotlin code generator. But yes, manual mapping is a good start as well. 😉 Btw: Here's the issue where we track To-Do's related to Kotlin. |
@lemonmojo I'm trying to do exactly that hahahaha Do you have any insights on the best way to do it, |
@gabriel-kozma I recently created some manual Kotlin/JNA bindings for a C API that includes function pointers. Hope that helps! |
That helps! |
hi @lemonmojo I have this branch I've created for implementing this feature https://github.com/gabriel-kozma/beyondnet/tree/feature/android-delegates main...gabriel-kozma:beyondnet:feature/android-delegates I was able to generate the interfaces, but I'm still unable to use it on code, are you able to shine a light on what I'm doing wrong? |
@gabriel-kozma So let me start by sharing a "trick" that is helpful during development of the generator. There's a sample project in the repository under Now, when you run the generator from within the IDE, the generated code for the samples will be updated in the ![]() Now for the actual new generated code... Generally, Kotlin requires 2 separate projections of the .NET APIs:
The reason for this split is that unlike Swift, Kotlin cannot directly interface with C code. It requires some kind of wrapper (pretty much like DllImport in C#). This can be achieved using JNA or the more complicated alternative JNI. We're using JNA in Beyond.NET because it's easier to integrate. So that's why you'll see Without the low-level JNA wrapper we can't build the high-level API. So first you have to hook into the JNA generator phase and generate all the code necessary to use the low-level C APIs. The callback interfaces that you already have are one part of this. There are two things that are not implemented correctly right now for them:
Let's use The C typedef looks like this (you can find this in
What you're currently generating though doesn't match the C API:
Once you fix that, you'll have to look into generating JNA definitions for the various APIs that each delegate exposes in C:
Once you have these wrapped in JNA code, you should be able to:
Once you have all of this in place, let me know and I can guide you through the next steps like memory management (the context and destructor functions of delegates) and eventually how to wrap all of this in a nice object-oriented Kotlin API. Good luck! 🍀 |
@lemonmojo , thank you! I was following the signature of the methods you've sent before, but now I've realized that i was missing the context I'll make the required changes and generate neccessary code |
Hi there, last week, I've posted this question and from what I've seen on the kotlin generated code, it doesn't generate the delegate invocation in kotlin
So this approach wouldn't work in Kotlin, is that correct or is there a workaround?
The text was updated successfully, but these errors were encountered: