Create a scala interpreter in the browser

My first contact with Scala went through the SimplyScala Tutorial : you don't need to install anything and you can just start the code. A few hours later I fell in love with the language ...

A few years later I wrote web documentation for the Scala library as a playback application. It would be great to create something like SimplyScala and integrate it into the documentation so that the user can enter Scala commands in the browser and return the result.

SimplyScala works like LotREPLS (an old Open-Source-Java-Project with multiple LOCs) in the Google App Engine.

Can I also create something like this on my own server without getting a security hole (f.ex. the user should not read files from the server ...)?

I just need the "base" of the Scala language without import, as in SimplyScala.

My first idea is to write my own SecurityManager and handle timeouts so that the user cannot consume too much server time. Is there an easier way or an existing open source project?

Or is it just wiser to advise the user to install Scala and work with the terminal, and not with the browser ?; -)

The Scala homepage presents a similar idea for a Play project for Summer of Code 2012 Scala Projects : but I can’t find any results.

+5
source share
4 answers

, http://www.scala-js-fiddle.com/ ( GitHub) , , !

: Scala, Scala.js, Scala, , .. .

+7

:

Scala , (?):

-, - :

Scalakata, Source GitHub.

, (. src/main/scala/com.github.masseguillaume/security) - (. src/main/scala/com.github.masseguillaume/service/KateEval.scala). , ...

+6

: libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value

(scala.tools.nsc.Global)

scala. compileSources

Repl

IMain

JSR-223

import javax.script.ScriptEngineManager
val e = new ScriptEngineManager().getEngineByName("scala")
e.put("n", 10)
e.eval("1 + n") // 11

Reflection Toolbox

import scala.reflect.runtime.{currentMirror => cm}
import scala.reflect.runtime.universe._
import scala.tools.reflect.ToolBox
val tb = cm.mkToolBox()
tb.eval(tb.parse("1+1"))
// res0: Any = 2

() (scala.tools.nsc.interactive.Global)

. doc

+2

All Articles