Skip to content

Instantly share code, notes, and snippets.

@bancek
Created June 5, 2013 16:28
Show Gist options
  • Save bancek/5715259 to your computer and use it in GitHub Desktop.
Save bancek/5715259 to your computer and use it in GitHub Desktop.
Calling Scala from Node.js
# Install node-java
# npm install java
# Create file Foo.scala
# case class Foo(bar: String, baz: String)
# and compile it
# scalac Foo.scala
java = require 'java'
java.classpath.push '/usr/share/java/scala-library.jar'
java.classpath.push '.'
# val foo = new Foo("lorem", "ipsum")
foo = java.newInstanceSync 'Foo', 'lorem', 'ipsum'
# foo.bar
foo.barSync() # 'lorem'
Foo = java.getStaticFieldValue('Foo$', 'MODULE$')
# val foo = Foo("bar", "baz")
foo = Foo.applySync('lorem', 'ipsum')
# foo.toString()
foo.toStringSync() # 'Foo(lorem,ipsum)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment