Make compiler installed by default for standard platforms.

This commit is contained in:
James Roseborough
2010-05-14 04:00:05 +00:00
parent ceb53253fb
commit 47b33aea08
17 changed files with 37 additions and 46 deletions

View File

@@ -125,10 +125,8 @@ The following pattern is used within Java SE
<pre> <pre>
import org.luaj.vm2.*; import org.luaj.vm2.*;
import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.*;
import org.luaj.vm2.compiler.LuaC;
String script = "examples/lua/hello.lua"; String script = "examples/lua/hello.lua";
LuaC.install();
LuaValue _G = JsePlatform.standardGlobals(); LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) ); _G.get("dofile").call( LuaValue.valueOf(script) );
</pre> </pre>
@@ -150,10 +148,8 @@ The for MIDlets the <em>JmePlatform</em> is used instead:
<pre> <pre>
import org.luaj.vm2.*; import org.luaj.vm2.*;
import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.*;
import org.luaj.vm2.compiler.LuaC;
String script = "examples/lua/hello.lua"; String script = "examples/lua/hello.lua";
LuaC.install();
LuaValue _G = JmePlatform.standardGlobals(); LuaValue _G = JmePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) ); _G.get("dofile").call( LuaValue.valueOf(script) );
</pre> </pre>
@@ -180,25 +176,27 @@ An ant script to build and run the midlet is in
<p> <p>
You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work. You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work.
<h2>Including the lua bytecode compiler</h2> <h2>Excluding the lua bytecode compiler</h2>
By default, the compiler is not included so as to minimize footprint. By default, the compiler is included whenever <em>standardGlobals()</em> or <em>debugGlobals()</em> are called.
Without a compiler, files can still be executed, but they must be compiled elsewhere beforehand. Without a compiler, files can still be executed, but they must be compiled elsewhere beforehand.
The "luac" utility is provided in the jse jar for this purpose, or a standard lua compiler can be used. The "luac" utility is provided in the jse jar for this purpose, or a standard lua compiler can be used.
<p> <p>
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
<em>standardGlobals()</em> or <em>debugGlobals()</em>
but instead initialize globals with including only those libraries
that are needed and omitting the line:
<pre> <pre>
org.luaj.vm2.compiler.LuaC.install(); org.luaj.vm2.compiler.LuaC.install();
</pre> </pre>
<p>
To omit the compiler, omit this line from your startup code.
<h2>Including the lua-to-Java-bytecode compiler</h2> <h2>Including the lua-to-Java-bytecode compiler</h2>
<p> <p>
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 <em>after</em> globals have been created using:
<pre> <pre>
org.luaj.vm2.jse.luajc.LuaJC.install(); org.luaj.vm2.jse.luajc.LuaJC.install();

View File

@@ -20,7 +20,6 @@ public class SampleMIDlet extends MIDlet {
script = DEFAULT_SCRIPT; script = DEFAULT_SCRIPT;
// create an environment to run in // create an environment to run in
LuaC.install();
LuaValue _G = JmePlatform.standardGlobals(); LuaValue _G = JmePlatform.standardGlobals();
_G.get("require").call( LuaValue.valueOf(script) ); _G.get("require").call( LuaValue.valueOf(script) );
} }

View File

@@ -1,8 +1,7 @@
import org.luaj.vm2.*; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.JsePlatform;
import org.luaj.vm2.compiler.LuaC;
public class SampleJseMain { public class SampleJseMain {
@@ -11,7 +10,6 @@ public class SampleJseMain {
String script = "examples/lua/hello.lua"; String script = "examples/lua/hello.lua";
// create an environment to run in // create an environment to run in
LuaC.install();
LuaValue _G = JsePlatform.standardGlobals(); LuaValue _G = JsePlatform.standardGlobals();
_G.get("dofile").call( LuaValue.valueOf(script) ); _G.get("dofile").call( LuaValue.valueOf(script) );
} }

View File

@@ -21,6 +21,7 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.vm2.lib; package org.luaj.vm2.lib;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread; import org.luaj.vm2.LuaThread;
import org.luaj.vm2.lib.jme.JmeIoLib; import org.luaj.vm2.lib.jme.JmeIoLib;
@@ -43,6 +44,7 @@ public class JmePlatform {
_G.load(new CoroutineLib()); _G.load(new CoroutineLib());
_G.load(new JmeIoLib()); _G.load(new JmeIoLib());
LuaThread.setGlobals(_G); LuaThread.setGlobals(_G);
LuaC.install();
return _G; return _G;
} }

View File

@@ -32,7 +32,6 @@ import org.luaj.vm2.Lua;
import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.JsePlatform; import org.luaj.vm2.lib.JsePlatform;
import org.luaj.vm2.luajc.LuaJC; import org.luaj.vm2.luajc.LuaJC;
@@ -65,7 +64,6 @@ public class lua {
// new lua state // new lua state
_G = JsePlatform.debugGlobals(); _G = JsePlatform.debugGlobals();
LuaC.install();
// process args // process args
boolean interactive = (args.length == 0); boolean interactive = (args.length == 0);

View File

@@ -21,6 +21,7 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.vm2.lib; package org.luaj.vm2.lib;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread; import org.luaj.vm2.LuaThread;
import org.luaj.vm2.lib.jse.JseBaseLib; import org.luaj.vm2.lib.jse.JseBaseLib;
@@ -48,6 +49,7 @@ public class JsePlatform {
_G.load(new JseOsLib()); _G.load(new JseOsLib());
_G.load(new LuajavaLib()); _G.load(new LuajavaLib());
LuaThread.setGlobals(_G); LuaThread.setGlobals(_G);
LuaC.install();
return _G; return _G;
} }

View File

@@ -63,10 +63,6 @@ public class LuaScriptEngine implements ScriptEngine, Compilable {
private static final String __ARGV__ = "arg"; private static final String __ARGV__ = "arg";
private static final String __FILENAME__ = "?"; private static final String __FILENAME__ = "?";
static {
LuaC.install();
}
private static final ScriptEngineFactory myFactory = new LuaScriptEngineFactory(); private static final ScriptEngineFactory myFactory = new LuaScriptEngineFactory();
private ScriptContext defaultContext; private ScriptContext defaultContext;

View File

@@ -25,10 +25,10 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import org.luaj.vm2.LuaClosure; import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.Print;
import org.luaj.vm2.Prototype;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue; 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.compiler.LuaC;
import org.luaj.vm2.lib.JsePlatform; import org.luaj.vm2.lib.JsePlatform;
@@ -53,7 +53,6 @@ public class TestLuaJ {
// create an environment to run in // create an environment to run in
LuaTable _G = JsePlatform.standardGlobals(); LuaTable _G = JsePlatform.standardGlobals();
LuaC.install();
// compile into a chunk, or load as a class // compile into a chunk, or load as a class
InputStream is = new ByteArrayInputStream( script.getBytes() ); InputStream is = new ByteArrayInputStream( script.getBytes() );

View File

@@ -82,7 +82,6 @@ public class CompatibiltyTest {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
System.setProperty("JME", "false"); System.setProperty("JME", "false");
LuaC.install();
} }
} }
public static class JseBytecodeTest extends CompatibiltyTestSuite { public static class JseBytecodeTest extends CompatibiltyTestSuite {

View File

@@ -40,7 +40,6 @@ public class ErrorsTest extends ScriptDrivenTest {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
LuaC.install();
} }
public void testBaseLibArgs() { runTest("baselibargs"); } public void testBaseLibArgs() { runTest("baselibargs"); }

View File

@@ -196,7 +196,6 @@ public class LuaOperationsTest extends TestCase {
LuaValue aaa = LuaValue.valueOf("aaa"); LuaValue aaa = LuaValue.valueOf("aaa");
LuaValue eee = LuaValue.valueOf("eee"); LuaValue eee = LuaValue.valueOf("eee");
LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals(); LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
LuaC.install();
LuaTable newenv = LuaValue.tableOf( new LuaValue[] { LuaTable newenv = LuaValue.tableOf( new LuaValue[] {
LuaValue.valueOf("a"), LuaValue.valueOf("aaa"), LuaValue.valueOf("a"), LuaValue.valueOf("aaa"),
LuaValue.valueOf("b"), LuaValue.valueOf("bbb"), } ); LuaValue.valueOf("b"), LuaValue.valueOf("bbb"), } );

View File

@@ -44,18 +44,15 @@ public class ScriptDrivenTest extends TestCase {
private final PlatformType platform; private final PlatformType platform;
private final String basedir; private final String basedir;
private LuaTable _G;
protected ScriptDrivenTest( PlatformType platform, String directory ) { protected ScriptDrivenTest( PlatformType platform, String directory ) {
this.platform = platform; this.platform = platform;
this.basedir = directory; this.basedir = directory;
initGlobals();
} }
// */ private void initGlobals() {
protected void runTest(String testName) {
try {
// create globals
LuaTable _G = null;
switch ( platform ) { switch ( platform ) {
default: default:
case JSE: case JSE:
@@ -66,8 +63,18 @@ public class ScriptDrivenTest extends TestCase {
_G = org.luaj.vm2.lib.JmePlatform.debugGlobals(); _G = org.luaj.vm2.lib.JmePlatform.debugGlobals();
break; break;
} }
}
protected void setUp() throws Exception {
super.setUp();
}
// */
protected void runTest(String testName) {
try {
// override print() // override print()
initGlobals();
final ByteArrayOutputStream output = new ByteArrayOutputStream(); final ByteArrayOutputStream output = new ByteArrayOutputStream();
final PrintStream oldps = BaseLib.instance.STDOUT; final PrintStream oldps = BaseLib.instance.STDOUT;
final PrintStream ps = new PrintStream( output ); final PrintStream ps = new PrintStream( output );

View File

@@ -30,7 +30,6 @@ abstract public class AbstractUnitTests extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
_G = JsePlatform.standardGlobals(); _G = JsePlatform.standardGlobals();
LuaC.install();
} }
protected void doTest(String file) { protected void doTest(String file) {

View File

@@ -32,7 +32,6 @@ public class DumpLoadEndianIntTest extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
_G = JsePlatform.standardGlobals(); _G = JsePlatform.standardGlobals();
LuaC.install();
DumpState.ALLOW_INTEGER_CASTING = false; DumpState.ALLOW_INTEGER_CASTING = false;
} }

View File

@@ -22,7 +22,6 @@ public class SimpleTests extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
_G = JsePlatform.standardGlobals(); _G = JsePlatform.standardGlobals();
LuaC.install();
} }
private void doTest( String script ) { private void doTest( String script ) {

View File

@@ -24,7 +24,6 @@ public class LuaJavaCoercionTest extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
_G = JsePlatform.standardGlobals(); _G = JsePlatform.standardGlobals();
LuaC.install();
} }
public void testJavaIntToLuaInt() { public void testJavaIntToLuaInt() {

View File

@@ -110,7 +110,6 @@ public class Luajvm1CompatibilityTest extends TestCase {
} }
} }
}); });
org.luaj.vm2.compiler.LuaC.install();
org.luaj.vm2.lib.BaseLib.instance.STDOUT = printStream; org.luaj.vm2.lib.BaseLib.instance.STDOUT = printStream;
_G.get("require").call(LuaValue.valueOf(test)); _G.get("require").call(LuaValue.valueOf(test));
printStream.flush(); printStream.flush();