simplify LuaCompiler interface and add Lua2Java utility class.
This commit is contained in:
@@ -56,9 +56,7 @@ public class TestLuaJ {
|
||||
|
||||
// compile into a chunk, or load as a class
|
||||
InputStream is = new ByteArrayInputStream( script.getBytes() );
|
||||
Prototype p = LuaC.compile(is, "script");
|
||||
print( p );
|
||||
LuaValue chunk = new LuaClosure(p,_G);
|
||||
LuaValue chunk = LuaC.instance.load(is, "script",_G);
|
||||
chunk.call();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package org.luaj.vm2;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.luaj.vm2.lua2java.Lua2Java;
|
||||
import org.luaj.vm2.luajc.LuaJC;
|
||||
|
||||
/**
|
||||
@@ -62,9 +63,21 @@ public class CompatibiltyTest {
|
||||
TestSuite suite = new TestSuite("Compatibility Tests");
|
||||
suite.addTest( new TestSuite( JseCompatibilityTest.class, "JSE Tests" ) );
|
||||
suite.addTest( new TestSuite( JmeCompatibilityTest.class, "JME Tests" ) );
|
||||
suite.addTest( new TestSuite( Lua2JavaTest.class, "Lua2Java Tests" ) );
|
||||
suite.addTest( new TestSuite( JseBytecodeTest.class, "JSE Bytecode Tests" ) );
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static class Lua2JavaTest extends CompatibiltyTestSuite {
|
||||
public Lua2JavaTest() {
|
||||
super(ScriptDrivenTest.PlatformType.LUA2JAVA);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setProperty("Lua2Java", "false");
|
||||
Lua2Java.install();
|
||||
}
|
||||
}
|
||||
|
||||
public static class JmeCompatibilityTest extends CompatibiltyTestSuite {
|
||||
public JmeCompatibilityTest() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class FragmentsTest extends TestCase {
|
||||
if ( true ) {
|
||||
chunk = LuaJC.getInstance().load(is,name,_G);
|
||||
} else {
|
||||
chunk = (new LuaC()).load( is, name, _G );
|
||||
chunk = LuaC.instance.load( is, name, _G );
|
||||
}
|
||||
Varargs actual = chunk.invoke();
|
||||
assertEquals( expected.narg(), actual.narg() );
|
||||
|
||||
@@ -181,7 +181,7 @@ public class LuaOperationsTest extends TestCase {
|
||||
try {
|
||||
LuaTable _G = org.luaj.vm2.lib.JsePlatform.standardGlobals();
|
||||
InputStream is = new ByteArrayInputStream(script.getBytes("UTF-8"));
|
||||
return LuaC.compile(is, name);
|
||||
return LuaC.instance.compile(is, name);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ScriptDrivenTest extends TestCase {
|
||||
public static final boolean nocompile = "true".equals(System.getProperty("nocompile"));
|
||||
|
||||
public enum PlatformType {
|
||||
JME, JSE, LUAJIT,
|
||||
JME, JSE, LUAJIT, LUA2JAVA,
|
||||
}
|
||||
|
||||
private final PlatformType platform;
|
||||
@@ -57,6 +57,7 @@ public class ScriptDrivenTest extends TestCase {
|
||||
default:
|
||||
case JSE:
|
||||
case LUAJIT:
|
||||
case LUA2JAVA:
|
||||
_G = org.luaj.vm2.lib.JsePlatform.debugGlobals();
|
||||
break;
|
||||
case JME:
|
||||
|
||||
@@ -54,7 +54,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
|
||||
// compile in memory
|
||||
InputStream is = new ByteArrayInputStream(lua);
|
||||
Prototype p = LuaC.compile(is, "@" + dir + "/" + file);
|
||||
Prototype p = LuaC.instance.compile(is, "@" + dir + "/" + file);
|
||||
String actual = protoToString(p);
|
||||
|
||||
// load expected value from jar
|
||||
@@ -97,7 +97,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
protected Prototype loadFromBytes(byte[] bytes, String script)
|
||||
throws IOException {
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
return LoadState.compile(is, script);
|
||||
return LoadState.loadBinaryChunk(is.read(), is, script);
|
||||
}
|
||||
|
||||
protected String protoToString(Prototype p) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.vm2.LoadState;
|
||||
import org.luaj.vm2.LuaClosure;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Prototype;
|
||||
@@ -83,10 +84,10 @@ public class DumpLoadEndianIntTest extends TestCase {
|
||||
|
||||
// compile into prototype
|
||||
InputStream is = new ByteArrayInputStream(script.getBytes());
|
||||
Prototype p = LuaC.compile(is, "script");
|
||||
Prototype p = LuaC.instance.compile(is, "script");
|
||||
|
||||
// double check script result before dumping
|
||||
LuaClosure f = new LuaClosure(p, _G);
|
||||
LuaFunction f = new LuaClosure(p, _G);
|
||||
LuaValue r = f.call();
|
||||
String actual = r.tojstring();
|
||||
assertEquals( expectedPriorDump, actual );
|
||||
@@ -107,8 +108,7 @@ public class DumpLoadEndianIntTest extends TestCase {
|
||||
|
||||
// load again using compiler
|
||||
is = new ByteArrayInputStream(dumped);
|
||||
p = LoadState.compile(is, "dumped");
|
||||
f = new LuaClosure(p, _G);
|
||||
f = LoadState.load(is, "dumped", _G);
|
||||
r = f.call();
|
||||
actual = r.tojstring();
|
||||
assertEquals( expectedPostDump, actual );
|
||||
|
||||
@@ -5,14 +5,11 @@ import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.vm2.LuaClosure;
|
||||
import org.luaj.vm2.LuaDouble;
|
||||
import org.luaj.vm2.LuaFunction;
|
||||
import org.luaj.vm2.LuaInteger;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Print;
|
||||
import org.luaj.vm2.Prototype;
|
||||
import org.luaj.vm2.lib.BaseLib;
|
||||
import org.luaj.vm2.lib.JsePlatform;
|
||||
|
||||
public class SimpleTests extends TestCase {
|
||||
@@ -27,12 +24,7 @@ public class SimpleTests extends TestCase {
|
||||
private void doTest( String script ) {
|
||||
try {
|
||||
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
||||
Prototype p = LuaC.compile( is, "script" );
|
||||
assertNotNull( p );
|
||||
Print.printCode( p );
|
||||
|
||||
// try running the code!
|
||||
LuaClosure c = new LuaClosure( p, _G );
|
||||
LuaFunction c = LuaC.instance.load( is, "script", _G );
|
||||
c.call();
|
||||
} catch ( Exception e ) {
|
||||
fail("i/o exception: "+e );
|
||||
|
||||
Reference in New Issue
Block a user