7

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 find a good interpretor that can do what i need but unsuccesfull. Is the exists an implementation of JSR-223 for Scala? Or may be someone know how to solve my problem. Thanks.

1

4 Answers 4

7

Official support in scala starts in version 2.11 as seen in this closed ticket: https://issues.scala-lang.org/browse/SI-874

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

Comments

3

This library: http://code.google.com/p/scalascriptengine/ may help solve your problem.

Comments

0

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();
  }
}

Comments

0

This is a solid ScriptingEngine implementation

1 Comment

The link gives 404 currently.

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.