Created
November 26, 2014 22:00
-
-
Save salomvary/f2fd97a8df20a953313c to your computer and use it in GitHub Desktop.
Scala❤Java❤JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* scalac Main.scala | |
* scala com.example.Main | |
*/ | |
package com.example | |
import java.util.function.Function | |
import javax.script.ScriptEngineManager | |
object Main extends App { | |
def echo(callback: Function[Int, Int]) = callback.apply(2) | |
val js = | |
""" | |
var Main = JavaImporter(com.example).Main | |
var response = Main.echo(function(two) { | |
return 40 + two; | |
}) | |
print(response) | |
""" | |
val engine = new ScriptEngineManager().getEngineByName("nashorn") | |
engine.eval(js) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment