Add ruby interop
This commit is contained in:
parent
5ef39e87c6
commit
118865e028
|
@ -8,7 +8,7 @@ buildscript {
|
|||
apply plugin: 'com.github.jruby-gradle.base'
|
||||
import com.github.jrubygradle.JRubyExec
|
||||
|
||||
defaultTasks 'runServer'
|
||||
defaultTasks 'runInterop'
|
||||
|
||||
/* Disabling the default repositories so we can ues the new (unreleased)
|
||||
* default rubygems proxy
|
||||
|
@ -42,6 +42,10 @@ task runDemo(type: JRubyExec) {
|
|||
script './demo.rb'
|
||||
}
|
||||
|
||||
task runInterop(type: JRubyExec) {
|
||||
script './rubyinterop.rb'
|
||||
}
|
||||
|
||||
task runServer(type: JRubyExec) {
|
||||
script './server.rb'
|
||||
systemProperties 'java.library.path' : "${buildDir}/native"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
print(example);
|
||||
print(example.callMethod('hello'));
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'java'
|
||||
java_import 'javax.script.ScriptEngineManager'
|
||||
java_import 'javax.script.ScriptContext'
|
||||
|
||||
class Example
|
||||
def hello
|
||||
return 'hello world from Ruby'
|
||||
end
|
||||
end
|
||||
|
||||
engine = ScriptEngineManager.new.get_engine_by_name('nashorn')
|
||||
engine.get_bindings(ScriptContext::ENGINE_SCOPE).put('example', Example.new)
|
||||
|
||||
|
||||
puts '-' * 30
|
||||
engine.eval(File.open('rubyinterop.js').read)
|
||||
puts '-' * 30
|
Loading…
Reference in New Issue