-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathScriptEngineInvocable.java
32 lines (25 loc) · 1.14 KB
/
ScriptEngineInvocable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package examples;
import com.github.rcaller.scriptengine.NamedArgument;
import static com.github.rcaller.scriptengine.NamedArgument.*;
import com.github.rcaller.scriptengine.RCallerScriptEngine;
import com.github.rcaller.util.Globals;
import java.util.ArrayList;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class ScriptEngineInvocable {
public static void main(String[] args) throws ScriptException, NoSuchMethodException{
new ScriptEngineInvocable();
}
public ScriptEngineInvocable() throws ScriptException, NoSuchMethodException{
Globals.detect_current_rscript();
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("RCaller");
ArrayList<NamedArgument> results = (ArrayList<NamedArgument>)
((Invocable)engine).invokeFunction("sqrt", Named("",25.0));
double[] val = (double[])results.get(0).getObj();
System.out.println("Result is "+ val[0]);
((RCallerScriptEngine)engine).close();
}
}