import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.*;
/*
This Tutorial is a tutorial for more advanced developers.
If you are currently just playing around with the Irrlicht
engine, please look at other examples first.
This tutorials shows how to use a ajavascript file for creating
and running an irrlicht universe.
*/
/**
* This program loads and executes the JavaScript program
*
* @author Sergey Nechaev (snechaev@javazing.com)
*/
public class TestScripting
{
private static final String SCRIPT_ENGINE_NAME = "js";
private static final String SCRIPT_FILE_NAME = "script/js.js";
private ScriptEngine jsEngine;
private ScriptEngineManager mgr;
static
{
System.loadLibrary("irrlicht_wrap");
}
public static void main(String[] args) throws Exception
{
new TestScripting();
}
public TestScripting() throws Exception
{
mgr = new ScriptEngineManager();
jsEngine = mgr.getEngineByExtension(SCRIPT_ENGINE_NAME);
// InputStream is = this.getClass().getResourceAsStream("js.js");
File file = new File(SCRIPT_FILE_NAME);
InputStream is = new BufferedInputStream(new FileInputStream(file));
Reader reader = new InputStreamReader(is);
jsEngine.eval(reader);
}
}