SCRIPTING / NOTES</>↗Scripting28 Jul 2009
This example demonstrate how you can access Java object from a script. We start by creating the ScriptEngine object. Then we obtain the Bindings object from the engine and set the polyglot.js.allowHostAccess options to true. We do this using the Bindings‘s put(String name, Object value) method. After that we can put Java object into the […]
SCRIPTING / NOTES</>↗Scripting28 Jul 2009
This example show you how you can obtain a script engine for a specific language name and specific language version. In the code below we try to obtain script engine instance for ECMAScript version ECMAScript 262 Edition 11. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngine; import javax.script.ScriptException; import java.util.List; public class ScriptEngineSearch { public […]
SCRIPTING / NOTES</>↗Scripting23 Jul 2009
This code demonstrate the use of Invocable interface to invoke a specific function of a script. The Invocable.invokeFunction() takes the function name with or without a parameter as the function’s parameter. The parameter value can be passed as a varargs. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; import javax.script.Invocable; public class InvokingFunction { public […]
SCRIPTING / NOTES</>↗Scripting20 Jul 2009
This example demonstrated how to evaluate script that stored on a file. As we know that the eval() method can also accept a Reader object we can then read the script file using FileReader and pass it as the parameter to the eval() method of the ScriptEngine for further evaluation. package org.kodejava.script; import javax.script.ScriptEngineManager; import […]
SCRIPTING / NOTES</>↗Scripting20 Jul 2009
package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngineFactory; import java.util.List; public class GetSupportedScriptingEngine { public static void main(String[] args) { // Creating an instance of ScriptEngineManager an get the list // of available ScriptEngineFactory. ScriptEngineManager manager = new ScriptEngineManager(); List<ScriptEngineFactory> factories = manager.getEngineFactories(); for (ScriptEngineFactory factory : fa...
SCRIPTING / NOTES</>↗Scripting19 Jul 2009
This example shows how to get an instance of ScriptEngine by the engine name. Below we are trying to obtain the GraalVM JavaScript engine. package org.kodejava.script; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; public class GettingScriptEngineByName { public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); // Obtain an instance of ScriptEngine using the […]