Re: [Java] Function binding
John Moeller <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Rene Rivera wrote: > John Moeller wrote: >> The compile-time approach or something similar is necessary to generate >> the native functions for a Java class; the arguments of the native >> function have to be declared -- that is, there isn't a "blob" of Java >> arguments that can be parsed at runtime. There are a couple of >> alternatives that I've thought about, but they aren't very attractive >> (at least to me). > > I had a long offline conversation with John about bindings, for context > we worked together long ago to rewrite the Mac Common Lisp binding code, > and we came up with a portable way of doing the Java bindings. Briefly... Out of curiosity, John who? I know it's not me. :) > Langbinding provides a JNI class that manages in a generic way > forwarding calls back and forth between the Java and C++ sides. When > loading a C++ module, the Langbinding class reads the class descriptions > from the C++ module and generates in memory bytecode for the Java side > of those classes that just calls to the Lanbinding central class to > package calls and forward through the Langbinging class. The Langbinding > class loads the freshly generated bytecode classes into the JVM. That's something that I hadn't thought about, but it's a cool idea. How would you package primitive arguments on the Java side? Boxed, then package them in an Object array, and unbox them on the native side? Or maybe package them in a class that had all the args? > The drawback to this approach is the additional translation layer, but > perhaps this is a reasonable trade off given the extra flexibility > gained. Honestly, I think that the common langbinding class is the best approach, given the current invocation architecture. You'd have a common class like this anyway, even if you could generate your forwarding functions at compile time, just to get the generated classes loaded and linked to them. At the very least, it's something that we could stumble through creating. Time for me to buy a couple books on bytecode. Any suggestions? > Now if someone could figure out how to generate bytecode to > directly call C/C++ function pointers this extra layer could be removed. Hm. What function pointer would it call? To have one with all the arguments to match, you'd have to generate the function it points to at compile time. Or did I miss your meaning? -- John Moeller [email protected] ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/