I\'m trying to use Scala as a script language, that will be called from java and after that I need to get some objects as a result of script execution.
I tried to fi
This library: http://code.google.com/p/scalascriptengine/ may help solve your problem.
This is a solid ScriptingEngine implementation
Official support in scala starts in version 2.11 as seen in this closed ticket: https://issues.scala-lang.org/browse/SI-874
To be able to run the Codesnippet mentioned in (How do I set up jsr223 scripting with scala as scripting language) I needed to make the following changes. I used Scala 2.11.0-M4
public static void main(String args[]){
ScriptEngine engine = new ScriptEngineManager().getEngineByName("scala");
// Set up Scriptenvironment to use the Java classpath
List nil = Nil$.MODULE$;
$colon$colon vals = $colon$colon$.MODULE$.apply((String) "true", nil);
((IMain)engine).settings().usejavacp().tryToSet(vals);ScriptContext.ENGINE_SCOPE);
engine.getContext().setAttribute("labelO", new Integer(4), ScriptContext.ENGINE_SCOPE);
try {
engine.eval("val label = labelO.asInstanceOf[Integer]\n"+
"println(\"ergebnis: \" + (2 + label ))");
} catch (ScriptException ex) {
ex.printStackTrace();
}
}