Is there a way to run pure scala code in a script tag

89 views Asked by At

Using the scalatags script tag I know I can define the following:

script("console.log('Running javascript code')")

But is there a way I can rather pass pure scala code instead? So something like the following:

script(println("Running scala code now"))
1

There are 1 answers

2
sjrd On BEST ANSWER

No, that is not possible.

You can achieve the same effect in a different way, by exporting a top-level function with the Scala code you want to run, then generate a script that calls that function:

object Exports {
  @JSExportTopLevel("dynamicScriptCode")
  def code(): Unit =
    println("Running Scala code now")
}

...

script("dynamicScriptCode();")