From: Lyndon Samson Date: 2004-11-17T19:08:24+09:00 Subject: Re: Ruby to C to another language (perhaps Java (I Don't Need JRuby)) Sounds like you are better off skipping the C/C++ layer and using something like shared memory/memory mapped files to communicate between ruby and java. You could use real threads, or some sort of co-routine. Simple solution would be to use XML, otherwise you'll need to write something that unpacks complex structures from byte arrays. BTW, your subject line is a little confusing, I thought the post would be about a Ruby to C translator. :-) On Wed, 17 Nov 2004 15:42:19 +0900, Zach Dennis wrote: > This posting is more for a learning thing then anything else at this > point. I've been playing with Java to C via JNI lately doing some pretty > basic tests; calling methods, getting and settings fields, passing > primitive types around, etc... > > A while back (a few months ago) I did some Ruby to C tests of pretty > much the same caliber. > > I would like to combine the two approaches and share some objects > between Ruby to C to Java and vise versa. I am not looking for the JVM > to be able to process ruby code. (no JRuby) > > Has anyone had a similar approach (even if it wasn't Java) where they > were able to wrap a few Objects and use C as the middle man to communicate? > > If so, did you have to embed the ruby compiler inside the *.so or *.dll > file when running the interpretor of the other language (i presume yes?) > and what was the level of difficulty (one word answers are fine. I can > live with easy, hard, difficult, if you want to share a whole paragraph > then please do)? > > Is it difficult to share data structures between three different > languages. Again Ruby/C/"3rd Language"? > > What I am trying to get out of this is in the long run is to be able to > have a few data structures that I can share between Ruby and Java, via > C. I currently have java application and I feel I could code quicker > certain aspects alot quicker in Ruby if only I could share a data > structure/object. Ideally I would like to do something like: > > ---In My Ruby Code--- > class StringProcessor > def process_str( str ) > #process > return process_str > end > end > > ---In my Java Code---- > class StringProcessor{ > public native String _processString( String str ); > public void processString( String str ){ > this._processString( str ); > } > public static void main( String[] args ){ > new StringProcessor().processString( aBigString ); > } > } > > -----In my C Code (pseudo)----- > Java_StringProcessor__processString jstring ( jstring str ){ > char c = jStringToCharArray( str ) > c = Ruby_StringProcessor_processString( c ) > return charToJString( c ) > } > > jStringToCharArray char[] ( jstring str ){ > char[] c > //convert > return c > } > > charToJString jstring( char[] c ) > jstring j > //convert > return j > } > > Ruby_StringProcessor_processString char[] ( rstring str ){ > char[] c; > //Process > return c; > } > > This is not a well thought out example. It's just off the top of my head. > > So does anyone know if this is possible? > > Thanks, > > Zach > >