// JClass1.java package com_ravnaandtines.jlayer; public class JClass1 { public JClass1() { } public int doSomething(String arg) { System.out.println("In "+this.getClass().toString()+".doSomething(), printing "+arg); return arg.length(); } }
//SClass.scala package com_ravnaandtines.slayer import com_ravnaandtines.jlayer class SClass(token: String) { private val in = new com_ravnaandtines.jlayer.JClass1() private val len = in.doSomething(token) Console.println(len) }
//Python.py import com_ravnaandtines.jlayer.JClass1 direct = com_ravnaandtines.jlayer.JClass1() val = direct.doSomething("from Jython") print val import com_ravnaandtines.slayer.SClass x = com_ravnaandtines.slayer.SClass("Hello Babel!")
Build the first into JavaLayer.jar and copy it alongside the second
\scala-2.6.1-final\bin\scalac -classpath .JavaLayer.jar -d classes SClass.scala cd classes "\Program Files\Java\jdk1.6.0\bin\jar.exe" -cf ..\ScalaLayer.jar .
Then run the last with the two jars and the scala runtime jar in your path
In class com_ravnaandtines.jlayer.JClass1.doSomething(), printing from Jython 11 In class com_ravnaandtines.jlayer.JClass1.doSomething(), printing Hello Babel! 12
I had hoped that I could do the same in .Net, but having built the J# JavaLayer.dll, I got
>\scala-2.6.1-final\bin\scalac-net -d classes -Xassem-path JavaLayer.dll SClass. scala error: error while loading Predef, type 'scala.Predef' is broken (scala.tools.nsc.symtab.Symbols$ClassSymbol cannot be cast to scala.runtime.Noth ing$) one error found
so haven't yet managed to make a Scala-derived DLL for IronPython to consume. And that doesn't look like something I might obviously have done wrong.
No comments:
Post a Comment