Created
April 8, 2014 06:18
-
-
Save rahul8590/10096506 to your computer and use it in GitHub Desktop.
Script Engine Which is currently supposed to be running lua code .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineFactory; | |
import javax.script.ScriptEngineManager; | |
import org.luaj.vm2.*; | |
import org.luaj.vm2.lib.jse.*; | |
import javax.script.CompiledScript; | |
import javax.script.Bindings; | |
import javax.script.Compilable; | |
public class ScriptEngineSample { | |
public static void main(String [] args) { | |
ScriptEngineManager sem = new ScriptEngineManager(); | |
ScriptEngine e = sem.getEngineByName("luaj"); | |
ScriptEngineFactory f = e.getFactory(); | |
String statement = "a = a + 4 ; return a;"; | |
try { | |
CompiledScript cs = ((Compilable)e).compile(statement); | |
//e.eval(statement); | |
Bindings b = e.createBindings(); | |
b.put("a",4); | |
long s = System.currentTimeMillis(); | |
cs.eval(b); | |
long end = System.currentTimeMillis(); | |
long estimatedTime = end - s ; | |
System.out.println(estimatedTime); | |
} | |
catch (Exception se ) { | |
System.out.println("script exception "); | |
} | |
} | |
} | |
//Needs luaj-jse-3.0-beta2.jar in order to execute this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment