Skip to content
Snippets Groups Projects
Commit c4ed58eb authored by Florian Angerer's avatar Florian Angerer
Browse files

Adapted tutorial to new Java interop function names.

parent 81c2a574
No related branches found
No related tags found
No related merge requests found
...@@ -24,17 +24,17 @@ ...@@ -24,17 +24,17 @@
print("Hello, World! (from file)") print("Hello, World! (from file)")
print("Creating a Java object in FastR") print("Creating a Java object in FastR")
clazz <- .fastr.java.class("java.util.Date") clazz <- new.java.class("java.util.Date")
obj <- .fastr.interop.new(clazz, .fastr.interop.toLong(as.integer(Sys.time())*1000)) obj <- new.external(clazz, as.external.long(as.integer(Sys.time())*1000))
print(obj$toString()) print(obj$toString())
# add classpath entry to be able to use our class # add classpath entry to be able to use our class
java.addClasspathEntry("build/classes") java.addToClasspath("build/classes")
clazz <- .fastr.java.class("com.oracle.truffle.r.JavaMessage") clazz <- new.java.class("com.oracle.truffle.r.JavaMessage")
obj <- .fastr.interop.new(clazz, "Hi there") obj <- new.external(clazz, "Hi there")
print(obj$getMessage()) print(obj$getMessage())
JS_MIME_TYPE <- "application/javascript" JS_MIME_TYPE <- "application/javascript"
.fastr.interop.eval(JS_MIME_TYPE, 'var s = "Hello from Javascript"; print(s)') eval.external(JS_MIME_TYPE, source='var s = "Hello from Javascript"; print(s)')
.fastr.interop.evalFile("JS/main.js", JS_MIME_TYPE) eval.external(JS_MIME_TYPE, path="JS/main.js")
...@@ -139,7 +139,7 @@ During stepping through the R program, you will also step into the Java code. ...@@ -139,7 +139,7 @@ During stepping through the R program, you will also step into the Java code.
Next, lines 31 to 35 in *R/main.r* instantiate an object of a class in our NetBeans Java project. Next, lines 31 to 35 in *R/main.r* instantiate an object of a class in our NetBeans Java project.
Before we can use our class *JavaMessage*, we need to add this project to the class path for the Java interoperability. Before we can use our class *JavaMessage*, we need to add this project to the class path for the Java interoperability.
This is done by statement `java.addClasspathEntry("build/classes")`. This is done by statement `java.addToClasspath("build/classes")`.
You can now also set a breakpoint in the `getMessage()` method and the debugger will halt on this breakpoint if the R expression `obj$getMessage()` is evaluated. You can now also set a breakpoint in the `getMessage()` method and the debugger will halt on this breakpoint if the R expression `obj$getMessage()` is evaluated.
Lines 38 and 39 further evaluate code of a different language, namely JavaScript. Lines 38 and 39 further evaluate code of a different language, namely JavaScript.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment