Make compiler installed by default for standard platforms.
This commit is contained in:
18
README.html
18
README.html
@@ -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();
|
||||||
|
|||||||
@@ -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) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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() );
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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"); }
|
||||||
|
|||||||
@@ -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"), } );
|
||||||
|
|||||||
@@ -44,30 +44,37 @@ 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() {
|
||||||
|
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) {
|
protected void runTest(String testName) {
|
||||||
try {
|
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()
|
// 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 );
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 ) {
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user