Re: [xwiki-devs] [scala-user] Re: JSR 223?
I asked the Scala group about the availability of a JSR-223 implementation, so that XWiki could make use of it. Below is one response, and here is the URL of the thread, in case other responses are added there in the meantime: http://old.nabble.com/JSR-223--td27529387.html Those who are familiar with JSR-223 might find it useful. Henry On 10 Feb 2010, at 13:33, michid wrote:
Story Henry <henry.story@...> writes:
I was just wondering if there is a good JSR-223 (plugin? Jar?) implementation for Scala. This would allow tools such as XWiki to easily make it available for scripting. Apparently if a language implements this, they can provide it just by placing a jar in a special directory. These are the jsr223 languages they support: Velocity, Groovy, Python, Ruby, PHP.
Henry,
I created a JSR-223 scripting engine for Apache Sling [1]. While it is used by Sling and is interoperable with OSGi, it can also be used independently from Sling and OSGi. The source is available from SVN [2] and there are some instructions [3] on how to use it though these are mainly targeted to Sling.
Note however, that the scripting engine is different from REPL scripting. It only accepts 'real' Scala source entities as input. I chose this approach in order to be able to use existing tools for developing scripts (i.e. editor, IDE, debugging, unit testing).
Michael
[1] http://sling.apache.org/site/index.html [2] http://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/scala/script/ [3] http://cwiki.apache.org/confluence/display/SLING/Using+Scala+with+Sling
Does it make sense to just have one main dynamic language interface -- groovy -- and then access other jvm langs through groovy? e.g.: http://groovy.codehaus.org/JSR-223+access+to+other+JVM+languages http://svn.codehaus.org/groovy/tags/cc/build.2126/src/wiki-snapshot.pdf Calling Scala from Groovy
First write a Scala class:
Complex.scala
class Complex(real: double, imaginary: double) { def re = real def im = imaginary override def toString() = "" + re + (if (im < 0) "" else "+") +
im + "i"
} Compile this using scalac: > scalac Complex.scala Now write our Groovy Program:
ComplexMain.groovy
println new Complex(1.2, 3.4) Now run the program (assuming scala-library.jar is in the CLASSPATH): > groovy ComplexMain Which produces: 1.2+3.4i Note that in this example it would have been just as easy to write our
Complex class using Groovy as follows:
class Complex { def re, im Complex (double real, double imaginary) { re = real im = imaginary } String toString() { "$re" + (im<0 ? '' : '+') + im + 'i' } } but in other cases you may have some existing Scala classes you wish to
reuse from Groovy.
Also note my interest in using Clojure with Xwiki: http://www.mail-archive.com/[email protected]/msg10589.html and an interesting response from the author of http://github.com/pmf/clojure-jsr223 : http://groups.google.com/group/clojure/msg/ad811b69d448e3db Due to lack of time, and overcommitment, I decided it would be best to let Xwiki and Clojure and JSR 223 mature some more, and learned to program in groovy instead (because it works and is "mature" in its xwiki integration)... -- Niels. http://nielsmayer.com
participants (2)
-
Niels Mayer -
Story Henry