Skip to content

Instantly share code, notes, and snippets.

@rahul8590
Created April 8, 2014 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul8590/10096506 to your computer and use it in GitHub Desktop.
Save rahul8590/10096506 to your computer and use it in GitHub Desktop.
Script Engine Which is currently supposed to be running lua code .
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