From: D-Man <ds...@ri...> - 2001-05-21 22:50:43
|
On Mon, May 21, 2001 at 02:56:52PM -0700, Harlan Hile wrote: | > Date: Fri, 18 May 2001 23:21:11 -0400 | > From: D-Man <ds...@ri...> | > You only need the @sig stuff if you want to access the _classes_ in | > the python module from a java class. The limitation to classes only | > (and not module-level stuff) is a result of java. | | So, what i've ended up doing is writing a small bit of java for the module | level stuff.. some constants and a few static methods. i have methods | that return the result of calling the constructors of the classes i have, | which are written in python and then jythonc'd. | This seems to work pretty well, but I had to make the constructors of the | classes accessible from java, which means i needed to make them inherit | from a java class. just having them inherit from Object didnt seem to | work, so they inherit from the classes i'm trying to wrap, which isnt | exactly what should happen, but it works OK. Could you share some of that python code? The following code works fine for me: ========== Foo.py ============== import java class Foo( java.lang.Object ) : def __init__( self ) : """ @sig public Foo() """ print "Foo.__init__" ========== Bar.java =========== class Bar { public static void main( String[] argv ) { System.out.println( "main ..." ) ; Foo obj = new Foo() ; System.out.println( "end of main" ) ; } } ====== shell (bash from cygwin on win2k) ======= $ jythonc Foo.py <jythonc output> $ javac2 -classpath .\;jpywork\;d:/apps/jython-2.0/jython.jar Bar.java $ java2 -classpath .\;jpywork\;d:/apps/jython-2.0/jython.jar Bar main ... Foo.__init__ end of main $ In this message you said that the java code must access the python code. In that case the @sig thing is needed. As you can see in the example, the @sig is rather simple -- it is placed in the method's docstring and contains the java signature that jythonc should generate. -D |