1

I have a little project with an editor, some special need I had and which I hacked together in an afternoon. A co-worker looked over my shoulder (don't you hate that?) and said "Oh neat, but can it do X?"

So, to combine my ever-lasting need to learn new things and to enable some extensions on that little editor, I want to put some simple manipulation functions into there. And thus, I want to enable some scripting.

I found some tutorials about the ScriptEngine, that is not the problem. The problem is that it seems only to support JavaScript via Rhino. I have them all installed via apt-get: JRuby, Jython, Groovy, but the ScriptEngine doesn't know them.

What I would prefer is dropping a dependency in my build.sbt. Maybe someone knows a way to do that properly?

And if I resume to JavaScript, can I safely assume Rhino is installed on every machine with a JDK?

1
  • 1
    You can safely assume Rhino is installed on every machine with a JDK version 6 or later (version 5 may also work) Commented Oct 7, 2011 at 8:25

2 Answers 2

1

Here is an article about embedding a Scala interpreter. This might be overkill for what you are doing, however.

http://suereth.blogspot.com/2009/04/embedding-scala-interpreter.html

You could also look at the scaladocs for an interpreter directly.

http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/compiler/scala/tools/nsc/interpreter/package.html

If they are really simple manipulation functions, you could write your own language using parser combinators.

http://www.codecommit.com/blog/scala/the-magic-behind-parser-combinators

Sign up to request clarification or add additional context in comments.

Comments

0

Stir some Groovy into your Java apps is a developerWorks tutorial which doesn't depend on ScriptEngine but instead uses groovy.lang.GroovyClassLoader - I had been meaning to try adapting this to Scala but hadn't got round to it yet (let me know how it goes).

When adapting it to Scala, remember that:

ClassLoader parent = CLEmbedGroovy.class.getClassLoader();

is written:

val parent: ClassLoader = classOf[CLEmbedGroovy].getClassLoader() 

Further down that article there are other interesting options such as GroovyScriptEngine. SBT-wise I think (source) you just need to drop in:

val groovyAll1.0Jsr = "groovy" % "groovy-all-1.0-jsr" % "05"

Good luck!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.