diff --git a/README.html b/README.html index dd30e2e3..0fdd7949 100644 --- a/README.html +++ b/README.html @@ -125,10 +125,8 @@ The following pattern is used within Java SE
import org.luaj.vm2.*;
import org.luaj.vm2.lib.*;
- import org.luaj.vm2.compiler.LuaC;
String script = "examples/lua/hello.lua";
- LuaC.install();
LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) );
@@ -150,10 +148,8 @@ The for MIDlets the JmePlatform is used instead:
import org.luaj.vm2.*;
import org.luaj.vm2.lib.*;
- import org.luaj.vm2.compiler.LuaC;
String script = "examples/lua/hello.lua";
- LuaC.install();
LuaValue _G = JmePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) );
@@ -180,25 +176,27 @@ An ant script to build and run the midlet is in
You must install the wireless toolkit and define WTK_HOME for this script to work. -
-To include the lua-to-lua-bytecode compiler, include the following sometime before lua source files are loaded: +To exclude the lua-to-lua-bytecode compiler, do not call +standardGlobals() or debugGlobals() +but instead initialize globals with including only those libraries +that are needed and omitting the line:
org.luaj.vm2.compiler.LuaC.install();-
-To omit the compiler, omit this line from your startup code.
-To compile from lua to Java bytecode for all lua loaded at runtime, use the LuaJC class: +To compile from lua to Java bytecode for all lua loaded at runtime, +install the LuaJC compiler after globals have been created using:
org.luaj.vm2.jse.luajc.LuaJC.install();
diff --git a/examples/jme/SampleMIDlet.java b/examples/jme/SampleMIDlet.java
index df2f4684..70060fd7 100644
--- a/examples/jme/SampleMIDlet.java
+++ b/examples/jme/SampleMIDlet.java
@@ -20,7 +20,6 @@ public class SampleMIDlet extends MIDlet {
script = DEFAULT_SCRIPT;
// create an environment to run in
- LuaC.install();
LuaValue _G = JmePlatform.standardGlobals();
_G.get("require").call( LuaValue.valueOf(script) );
}
diff --git a/examples/jse/SampleJseMain.java b/examples/jse/SampleJseMain.java
index a014c930..61ab10b2 100644
--- a/examples/jse/SampleJseMain.java
+++ b/examples/jse/SampleJseMain.java
@@ -1,8 +1,7 @@
-import org.luaj.vm2.*;
-import org.luaj.vm2.lib.*;
-import org.luaj.vm2.compiler.LuaC;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.JsePlatform;
public class SampleJseMain {
@@ -11,7 +10,6 @@ public class SampleJseMain {
String script = "examples/lua/hello.lua";
// create an environment to run in
- LuaC.install();
LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) );
}
diff --git a/src/jme/org/luaj/vm2/lib/JmePlatform.java b/src/jme/org/luaj/vm2/lib/JmePlatform.java
index e43ce7f1..5f5a84ee 100644
--- a/src/jme/org/luaj/vm2/lib/JmePlatform.java
+++ b/src/jme/org/luaj/vm2/lib/JmePlatform.java
@@ -21,6 +21,7 @@
******************************************************************************/
package org.luaj.vm2.lib;
+import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread;
import org.luaj.vm2.lib.jme.JmeIoLib;
@@ -43,6 +44,7 @@ public class JmePlatform {
_G.load(new CoroutineLib());
_G.load(new JmeIoLib());
LuaThread.setGlobals(_G);
+ LuaC.install();
return _G;
}
diff --git a/src/jse/lua.java b/src/jse/lua.java
index 9d26c0b7..fe5eea3b 100644
--- a/src/jse/lua.java
+++ b/src/jse/lua.java
@@ -32,7 +32,6 @@ import org.luaj.vm2.Lua;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
-import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.JsePlatform;
import org.luaj.vm2.luajc.LuaJC;
@@ -65,7 +64,6 @@ public class lua {
// new lua state
_G = JsePlatform.debugGlobals();
- LuaC.install();
// process args
boolean interactive = (args.length == 0);
diff --git a/src/jse/org/luaj/vm2/lib/JsePlatform.java b/src/jse/org/luaj/vm2/lib/JsePlatform.java
index bb71a539..135b9d80 100644
--- a/src/jse/org/luaj/vm2/lib/JsePlatform.java
+++ b/src/jse/org/luaj/vm2/lib/JsePlatform.java
@@ -21,6 +21,7 @@
******************************************************************************/
package org.luaj.vm2.lib;
+import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread;
import org.luaj.vm2.lib.jse.JseBaseLib;
@@ -48,6 +49,7 @@ public class JsePlatform {
_G.load(new JseOsLib());
_G.load(new LuajavaLib());
LuaThread.setGlobals(_G);
+ LuaC.install();
return _G;
}
diff --git a/src/jse/org/luaj/vm2/script/LuaScriptEngine.java b/src/jse/org/luaj/vm2/script/LuaScriptEngine.java
index 57a77e65..3b04d1d6 100644
--- a/src/jse/org/luaj/vm2/script/LuaScriptEngine.java
+++ b/src/jse/org/luaj/vm2/script/LuaScriptEngine.java
@@ -63,10 +63,6 @@ public class LuaScriptEngine implements ScriptEngine, Compilable {
private static final String __ARGV__ = "arg";
private static final String __FILENAME__ = "?";
- static {
- LuaC.install();
- }
-
private static final ScriptEngineFactory myFactory = new LuaScriptEngineFactory();
private ScriptContext defaultContext;
diff --git a/test/java/org/luaj/luajc/TestLuaJ.java b/test/java/org/luaj/luajc/TestLuaJ.java
index 2b98eb93..20ab2482 100644
--- a/test/java/org/luaj/luajc/TestLuaJ.java
+++ b/test/java/org/luaj/luajc/TestLuaJ.java
@@ -25,10 +25,10 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.luaj.vm2.LuaClosure;
-import org.luaj.vm2.Print;
-import org.luaj.vm2.Prototype;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Print;
+import org.luaj.vm2.Prototype;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.JsePlatform;
@@ -53,7 +53,6 @@ public class TestLuaJ {
// create an environment to run in
LuaTable _G = JsePlatform.standardGlobals();
- LuaC.install();
// compile into a chunk, or load as a class
InputStream is = new ByteArrayInputStream( script.getBytes() );
diff --git a/test/junit/org/luaj/vm2/CompatibiltyTest.java b/test/junit/org/luaj/vm2/CompatibiltyTest.java
index fa8335bc..7d4c1194 100644
--- a/test/junit/org/luaj/vm2/CompatibiltyTest.java
+++ b/test/junit/org/luaj/vm2/CompatibiltyTest.java
@@ -82,7 +82,6 @@ public class CompatibiltyTest {
protected void setUp() throws Exception {
super.setUp();
System.setProperty("JME", "false");
- LuaC.install();
}
}
public static class JseBytecodeTest extends CompatibiltyTestSuite {
diff --git a/test/junit/org/luaj/vm2/ErrorsTest.java b/test/junit/org/luaj/vm2/ErrorsTest.java
index 1715c1d3..c0fbb344 100644
--- a/test/junit/org/luaj/vm2/ErrorsTest.java
+++ b/test/junit/org/luaj/vm2/ErrorsTest.java
@@ -40,7 +40,6 @@ public class ErrorsTest extends ScriptDrivenTest {
protected void setUp() throws Exception {
super.setUp();
- LuaC.install();
}
public void testBaseLibArgs() { runTest("baselibargs"); }
diff --git a/test/junit/org/luaj/vm2/LuaOperationsTest.java b/test/junit/org/luaj/vm2/LuaOperationsTest.java
index fd3799da..9ab8e09e 100644
--- a/test/junit/org/luaj/vm2/LuaOperationsTest.java
+++ b/test/junit/org/luaj/vm2/LuaOperationsTest.java
@@ -196,7 +196,6 @@ public class LuaOperationsTest extends TestCase {
LuaValue aaa = LuaValue.valueOf("aaa");
LuaValue eee = LuaValue.valueOf("eee");
LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
- LuaC.install();
LuaTable newenv = LuaValue.tableOf( new LuaValue[] {
LuaValue.valueOf("a"), LuaValue.valueOf("aaa"),
LuaValue.valueOf("b"), LuaValue.valueOf("bbb"), } );
diff --git a/test/junit/org/luaj/vm2/ScriptDrivenTest.java b/test/junit/org/luaj/vm2/ScriptDrivenTest.java
index 1ba7bbf2..f6816274 100644
--- a/test/junit/org/luaj/vm2/ScriptDrivenTest.java
+++ b/test/junit/org/luaj/vm2/ScriptDrivenTest.java
@@ -44,30 +44,37 @@ public class ScriptDrivenTest extends TestCase {
private final PlatformType platform;
private final String basedir;
+ private LuaTable _G;
protected ScriptDrivenTest( PlatformType platform, String directory ) {
this.platform = platform;
this.basedir = directory;
+ initGlobals();
}
+ private void initGlobals() {
+ switch ( platform ) {
+ default:
+ case JSE:
+ case LUAJIT:
+ _G = org.luaj.vm2.lib.JsePlatform.debugGlobals();
+ break;
+ case JME:
+ _G = org.luaj.vm2.lib.JmePlatform.debugGlobals();
+ break;
+ }
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
// */
protected void runTest(String testName) {
try {
-
- // create globals
- LuaTable _G = null;
- switch ( platform ) {
- default:
- case JSE:
- case LUAJIT:
- _G = org.luaj.vm2.lib.JsePlatform.debugGlobals();
- break;
- case JME:
- _G = org.luaj.vm2.lib.JmePlatform.debugGlobals();
- break;
- }
-
// override print()
+ initGlobals();
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final PrintStream oldps = BaseLib.instance.STDOUT;
final PrintStream ps = new PrintStream( output );
diff --git a/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java b/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
index f72f02bc..22f85c27 100644
--- a/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
+++ b/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
@@ -30,7 +30,6 @@ abstract public class AbstractUnitTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
_G = JsePlatform.standardGlobals();
- LuaC.install();
}
protected void doTest(String file) {
diff --git a/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java b/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
index 284b958d..ff22caf0 100644
--- a/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
+++ b/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
@@ -32,7 +32,6 @@ public class DumpLoadEndianIntTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
_G = JsePlatform.standardGlobals();
- LuaC.install();
DumpState.ALLOW_INTEGER_CASTING = false;
}
diff --git a/test/junit/org/luaj/vm2/compiler/SimpleTests.java b/test/junit/org/luaj/vm2/compiler/SimpleTests.java
index 51440be4..0c632ee1 100644
--- a/test/junit/org/luaj/vm2/compiler/SimpleTests.java
+++ b/test/junit/org/luaj/vm2/compiler/SimpleTests.java
@@ -22,7 +22,6 @@ public class SimpleTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
_G = JsePlatform.standardGlobals();
- LuaC.install();
}
private void doTest( String script ) {
diff --git a/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java b/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
index ac87da88..3ca1bcd6 100644
--- a/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
+++ b/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
@@ -24,7 +24,6 @@ public class LuaJavaCoercionTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
_G = JsePlatform.standardGlobals();
- LuaC.install();
}
public void testJavaIntToLuaInt() {
diff --git a/test/junit/org/luaj/vm2/vm1/Luajvm1CompatibilityTest.java b/test/junit/org/luaj/vm2/vm1/Luajvm1CompatibilityTest.java
index 0c3609f4..f1d446de 100644
--- a/test/junit/org/luaj/vm2/vm1/Luajvm1CompatibilityTest.java
+++ b/test/junit/org/luaj/vm2/vm1/Luajvm1CompatibilityTest.java
@@ -110,7 +110,6 @@ public class Luajvm1CompatibilityTest extends TestCase {
}
}
});
- org.luaj.vm2.compiler.LuaC.install();
org.luaj.vm2.lib.BaseLib.instance.STDOUT = printStream;
_G.get("require").call(LuaValue.valueOf(test));
printStream.flush();