Replies: 3 comments 2 replies
-
I'm not sure I get what you mean. Do you mean like a way to generate classes on the fly? Why would you need this with JNR-FFI? |
Beta Was this translation helpful? Give feedback.
-
No, the interface classes, for example class libclass{ this is kotlin so it might look foreign for you, but its the same same concept as the stuff in your readme because this code is very simple and can be easily generated and can be annoying to maintain as you add and remove functions |
Beta Was this translation helpful? Give feedback.
-
Ah I see what you mean, you mean something akin to JNAerator but for JNR-FFI. Like a tool to autogenerate the binding code based on the native header files. Sorry, we don't have something like that I'm afraid, and I don't think it's in our long term plan either. There is value in doing the binding by hand as a tool like JNAerator will sometimes not provide optimal or human readable mappings, I know this from experience, generally the code JNAerator produced was only about 40% optimal without needing to be touched or modified in my case. It's also good to have as few native bindings as you need and JNAerator encourages you to have bindings for the whole library (or at least every header you give it). I am aware of the pain it takes to do mappings though, especially for many large structs, it can be very painstaking and boring. But it means you are doing the code yourself, you are aware of all the parts and you are encouraged to have minimal mappings as a result. You are free to create your own tool (or fork JNAerator and update it for JNR-FFI) for this task. Generally JNAerator will do a lot of the boring grunt work for you, but converting from JNA to JNR-FFI might take more effort than doing it manually. Even if you used JNAerator and used JNA and not JNR-FFI, the code may not be optimal (JNAerator has been stale for a long time) so you might as well do it yourself. It's actually kind of similar to converting a Java file to Kotlin using IntelliJ's convert to Kotlin tool. It does a lot of the boring grunt work but it's never optimal or idiomatic Kotlin and you're forced to go over it and change it, the effort you put into doing so, may sometimes even be more than the effort it would have taken to do it manually (I know this from experience too). Sorry if this isn't the answer you were hoping for, out of curiosity, how large is the library you're trying to bind? Generally, like I said, the biggest hassle is converting all the structs, especially all of the ones that depend on each other and drawing a dependency graph to know what you need to bind first or even at all. |
Beta Was this translation helpful? Give feedback.
-
I wrote a python script, quick a dirty style, which generates a kotlin class based on nim files.
((this is not a purposed thing for my code! im just showing an example))
https://haste.zneix.eu/cekuqarova
I haven't tried any complex classes, ie maps and lists, and so it works off a simple dictionary to convert between types
Is there any builtin way for this to be done within the library, has this been considered? the basic code for library loading is really simple.
Beta Was this translation helpful? Give feedback.
All reactions