Embed JavaScript (J2v8)
if( ((String)langCombo.getSelectedItem()).equalsIgnoreCase("javascript") ) {
SwingUtilities.invokeLater(() -> {
try {
boolean useNodeJS = false;
V8 v8;
if( useNodeJS ) {
NodeJS nodeJS = NodeJS.createNodeJS();
v8 = nodeJS.getRuntime();
} else {
v8 = V8.createV8Runtime();
}
v8.registerJavaMethod(j8print, "write");
v8.registerJavaMethod(j8println, "writeln");
outputPrintLn("<START Javascript>");
v8.executeObjectScript(textTab.getSelectedTextView().getText());
outputPrintLn("<END Javascript>");
} catch (Exception e) {
e.printStackTrace();
outputPrintLn("error\n" + e.getMessage());
}
});
}
JavaVoidCallback j8print = new JavaVoidCallback() {
public void invoke(final V8Object receiver, final V8Array parameters) {
if (parameters.length() > 0) {
Object arg1 = parameters.get(0);
outputPrint((String)arg1);
if (arg1 instanceof Releasable) {
((Releasable) arg1).release();
}
}
}
};
JavaVoidCallback j8println = new JavaVoidCallback() {
public void invoke(final V8Object receiver, final V8Array parameters) {
if (parameters.length() > 0) {
Object arg1 = parameters.get(0);
outputPrintLn((String)arg1);
if (arg1 instanceof Releasable) {
((Releasable) arg1).release();
}
}
}
};