mardi 31 mars 2015

Scala script in 2.11

I have found an example code for a Scala runtime scripting in answer to Generating a class from string and instantiating it in Scala 2.10, however the code seems to be obsolete for 2.11 - I cannot find any function corresponding to build.setTypeSignature. Even if it worked, the code seems hard to read and follow to me.


How can Scala scripts be compiled and executed in Scala 2.11?


Let us assume I want following:



  • define several variables (names and values)

  • compile script

  • (optional improvement) change variable values

  • execute script


For simplicity consider following example:


I want to define following variables (programmatically, from the code, not from the script text):



val a = 1
val s = "String"


I want a following script to be compiled and on execution a String value "a is 1, s is String" returned from it:



s"a is $a, s is $s"


How should my functions look like?



def setupVariables() = ???

def compile() = ???

def changeVariables() = ???

def execute() : String = ???





Aucun commentaire:

Enregistrer un commentaire