diff --git a/README.html b/README.html
index 949a61ed..554f92b1 100644
--- a/README.html
+++ b/README.html
@@ -978,6 +978,7 @@ Files are no longer hosted at LuaForge.
Fix aliasing issue for some multiple assignments from varargs return values (fixes issue #38)
Let os.getenv() return System.getenv() values first for JSE, then fall back to properties (fixes issue #25)
Improve collection of orphaned coroutines when yielding from debug hook functions.
+LuaScriptEngineFactory.getScriptEngine() now returns new instance of lua script engine for each call.
diff --git a/src/jse/org/luaj/vm2/script/LuaScriptEngineFactory.java b/src/jse/org/luaj/vm2/script/LuaScriptEngineFactory.java
index 83df7486..2e3e194a 100644
--- a/src/jse/org/luaj/vm2/script/LuaScriptEngineFactory.java
+++ b/src/jse/org/luaj/vm2/script/LuaScriptEngineFactory.java
@@ -28,7 +28,10 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
/**
- * Jsr 223 scripting engine factory
+ * Jsr 223 scripting engine factory.
+ *
+ * Exposes metadata to support the lua language, and constructs
+ * instances of LuaScriptEngine to handl lua scripts.
*/
public class LuaScriptEngineFactory implements ScriptEngineFactory {
@@ -47,12 +50,9 @@ public class LuaScriptEngineFactory implements ScriptEngineFactory {
"luaj",
};
- private static final ThreadLocal engines
- = new ThreadLocal();
private List extensions;
private List mimeTypes;
private List names;
-
public LuaScriptEngineFactory() {
extensions = Arrays.asList(EXTENSIONS);
@@ -123,11 +123,6 @@ public class LuaScriptEngineFactory implements ScriptEngineFactory {
}
public ScriptEngine getScriptEngine() {
- ScriptEngine eng = engines.get();
- if ( eng == null ) {
- eng = new LuaScriptEngine();
- engines.set(eng);
- }
- return eng;
+ return new LuaScriptEngine();
}
}
diff --git a/test/junit/org/luaj/vm2/script/ScriptEngineTests.java b/test/junit/org/luaj/vm2/script/ScriptEngineTests.java
index 0756f701..102c2874 100644
--- a/test/junit/org/luaj/vm2/script/ScriptEngineTests.java
+++ b/test/junit/org/luaj/vm2/script/ScriptEngineTests.java
@@ -46,12 +46,13 @@ public class ScriptEngineTests extends TestSuite {
public static TestSuite suite() {
TestSuite suite = new TestSuite("Script Engine Tests");
- suite.addTest( new TestSuite( LookupEngineTestCase.class, "Lookup Engine" ) );
- suite.addTest( new TestSuite( SimpleBindingsTest.class, "Simple Bindings" ) );
- suite.addTest( new TestSuite( DefaultBindingsTest.class, "Default Bindings" ) );
- suite.addTest( new TestSuite( LuaJCBindingsTest.class, "LuaJC Bindings" ) );
- suite.addTest( new TestSuite( UserContextTest.class, "User Context" ) );
- suite.addTest( new TestSuite( WriterTest.class, "Writer" ) );
+ suite.addTest( new TestSuite( LookupEngineTestCase.class, "Lookup Engine" ) );
+ suite.addTest( new TestSuite( DefaultBindingsTest.class, "Default Bindings" ) );
+ suite.addTest( new TestSuite( SimpleBindingsTest.class, "Simple Bindings" ) );
+ suite.addTest( new TestSuite( CompileClosureTest.class, "Compile Closure" ) );
+ suite.addTest( new TestSuite( CompileNonClosureTest.class, "Compile NonClosure" ) );
+ suite.addTest( new TestSuite( UserContextTest.class, "User Context" ) );
+ suite.addTest( new TestSuite( WriterTest.class, "Writer" ) );
return suite;
}
@@ -81,35 +82,39 @@ public class ScriptEngineTests extends TestSuite {
}
}
- public static class SimpleBindingsTest extends EngineTestCase {
- protected Bindings createBindings() {
- return new SimpleBindings();
- }
- public void testCompiledFunctionIsClosure() throws ScriptException {
- CompiledScript cs = ((Compilable)e).compile("return 'foo'");
- assertTrue(((LuaScriptEngine.LuajCompiledScript)cs).function.isclosure());
- }
- }
-
public static class DefaultBindingsTest extends EngineTestCase {
protected Bindings createBindings() {
return e.createBindings();
}
}
- public static class LuaJCBindingsTest extends EngineTestCase {
- static {
- System.setProperty("org.luaj.luajc", "true");
- }
+ public static class SimpleBindingsTest extends EngineTestCase {
protected Bindings createBindings() {
return new SimpleBindings();
}
- public void setUp() {
+ }
+
+ public static class CompileClosureTest extends DefaultBindingsTest {
+ protected void setUp() throws Exception {
+ System.setProperty("org.luaj.luajc", "false");
+ super.setUp();
+ }
+ public void testCompiledFunctionIsClosure() throws ScriptException {
+ CompiledScript cs = ((Compilable)e).compile("return 'foo'");
+ LuaValue value = ((LuaScriptEngine.LuajCompiledScript)cs).function;
+ assertTrue(value.isclosure());
+ }
+ }
+
+ public static class CompileNonClosureTest extends DefaultBindingsTest {
+ protected void setUp() throws Exception {
+ System.setProperty("org.luaj.luajc", "true");
super.setUp();
}
public void testCompiledFunctionIsNotClosure() throws ScriptException {
CompiledScript cs = ((Compilable)e).compile("return 'foo'");
- assertFalse(((LuaScriptEngine.LuajCompiledScript)cs).function.isclosure());
+ LuaValue value = ((LuaScriptEngine.LuajCompiledScript)cs).function;
+ assertFalse(value.isclosure());
}
}
@@ -117,7 +122,7 @@ public class ScriptEngineTests extends TestSuite {
protected ScriptEngine e;
protected Bindings b;
abstract protected Bindings createBindings();
- public void setUp() {
+ protected void setUp() throws Exception {
this.e = new ScriptEngineManager().getEngineByName("luaj");
this.b = createBindings();
}