diff --git a/.classpath b/.classpath
index 4430e29d..15cb3fb9 100644
--- a/.classpath
+++ b/.classpath
@@ -14,5 +14,6 @@
+
diff --git a/bin/LuaJit0.class b/bin/LuaJit0.class
deleted file mode 100644
index dd42a993..00000000
Binary files a/bin/LuaJit0.class and /dev/null differ
diff --git a/src/core/org/luaj/vm2/Print.java b/src/core/org/luaj/vm2/Print.java
index afdad44d..4f7ea48d 100644
--- a/src/core/org/luaj/vm2/Print.java
+++ b/src/core/org/luaj/vm2/Print.java
@@ -30,7 +30,7 @@ public class Print extends Lua {
private static final String STRING_FOR_NULL = "null";
public static PrintStream ps = System.out;
- private static final String[] luaP_opnames = {
+ public static final String[] OPNAMES = {
"MOVE",
"LOADK",
"LOADBOOL",
@@ -159,7 +159,7 @@ public class Print extends Lua {
ps.print("[" + line + "] ");
else
ps.print("[-] ");
- ps.print(luaP_opnames[o] + " ");
+ ps.print(OPNAMES[o] + " ");
switch (getOpMode(o)) {
case iABC:
ps.print( a );
diff --git a/src/test/compile/repack.sh b/src/test/compile/repack.sh
deleted file mode 100644
index a7dd2d77..00000000
--- a/src/test/compile/repack.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-LUA_HOME=/cygdrive/c/programs/lua5.1
-#DIRS="lua5.1-tests regressions"
-DIRS="regressions"
-for d in $DIRS; do
-
- # clean out the old
- rm -f $d/*.luac
-
- # compile the tests
- TESTS=`echo $d/*.lua`
- for x in $TESTS; do
- echo compiling $x
- luac -o ${x}c ${x}
- done
-
- # rebuild the directory
- rm -f ${d}.zip
- jar -cvf ${d}.zip ${d}
-done
\ No newline at end of file
diff --git a/src/test/compile/unpack.sh b/src/test/compile/unpack.sh
deleted file mode 100644
index ffe81bf4..00000000
--- a/src/test/compile/unpack.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-LUA_HOME=/cygdrive/c/programs/lua5.1
-#DIRS="lua5.1-tests regressions"
-DIRS="regressions"
-for d in $DIRS; do
-
- # unpack files into the directory
- rm -rf $d
- mkdir -p $d
- jar -xvf $d.zip
-
-done
\ No newline at end of file
diff --git a/src/test/java/org/luaj/vm/CompatibiltyTest.java b/src/test/java/org/luaj/vm/CompatibiltyTest.java
deleted file mode 100644
index 59b68aa9..00000000
--- a/src/test/java/org/luaj/vm/CompatibiltyTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-package org.luaj.vm;
-
-import java.io.IOException;
-
-/**
- * Compatibility tests for the Luaj VM
- *
- * Results are compared for exact match with
- * the installed C-based lua environment.
- */
-public class CompatibiltyTest extends ScriptDrivenTest {
-
- private static final String dir = "src/test/res";
-
- public CompatibiltyTest() {
- super(dir);
- }
-
- public void testTest1() throws IOException, InterruptedException {
- runTest("test1");
- }
-
- public void testTest2() throws IOException, InterruptedException {
- runTest("test2");
- }
-
- public void testTest3() throws IOException, InterruptedException {
- runTest("test3");
- }
-
- public void testTest4() throws IOException, InterruptedException {
- runTest("test4");
- }
-
- public void testTest5() throws IOException, InterruptedException {
- runTest("test5");
- }
-
- public void testTest6() throws IOException, InterruptedException {
- runTest("test6");
- }
-
- public void testTest7() throws IOException, InterruptedException {
- runTest("test7");
- }
-
- public void testTest8() throws IOException, InterruptedException {
- runTest("test8");
- }
-
- public void testTest9() throws IOException, InterruptedException {
- runTest("test9");
- }
-
- public void testAutoload() throws IOException, InterruptedException {
- runTest("autoload");
- }
-
- public void testBaseLib() throws IOException, InterruptedException {
- runTest("baselib");
- }
-
- public void testBoolean() throws IOException, InterruptedException {
- runTest("boolean");
- }
-
- public void testCalls() throws IOException, InterruptedException {
- runTest("calls");
- }
-
- public void testCoercions() throws IOException, InterruptedException {
- runTest("coercions");
- }
-
- public void testCoroutines() throws IOException, InterruptedException {
- runTest("coroutines");
- }
-
- public void testCompare() throws IOException, InterruptedException {
- runTest("compare");
- }
-
- public void testDebugLib() throws IOException, InterruptedException {
- runTest("debuglib");
- }
-
- public void testErrors() throws IOException, InterruptedException {
- runTest("errors");
- }
-
- public void testHugeTable() throws IOException, InterruptedException {
- runTest("hugetable");
- }
-
- public void testIoLib() throws IOException, InterruptedException {
- runTest("iolib");
- }
-
- public void testLoops() throws IOException, InterruptedException {
- runTest("loops");
- }
-
- public void testManyLocals() throws IOException, InterruptedException {
- runTest("manylocals");
- }
-
- public void testMathLib() throws IOException, InterruptedException {
- runTest("mathlib");
- }
-
- public void testMetatables() throws IOException, InterruptedException {
- runTest("metatables");
- }
-
- public void testModule() throws IOException, InterruptedException {
- runTest("module");
- }
-
- public void testNext() throws IOException, InterruptedException {
- runTest("next");
- }
-
- public void testOsLib() throws IOException, InterruptedException {
- runTest("oslib");
- }
-
- public void testPcalls() throws IOException, InterruptedException {
- runTest("pcalls");
- }
-
- public void testPrint() throws IOException, InterruptedException {
- runTest("print");
- }
-
- public void testRequire() throws IOException, InterruptedException {
- runTest("require");
- }
-
- public void testSelect() throws IOException, InterruptedException {
- runTest("select");
- }
-
- public void testSetfenv() throws IOException, InterruptedException {
- runTest("setfenv");
- }
-
- public void testSetlist() throws IOException, InterruptedException {
- runTest("setlist");
- }
-
- public void testSimpleMetatables() throws IOException, InterruptedException {
- runTest("simplemetatables");
- }
-
- public void testStack() throws IOException, InterruptedException {
- runTest("stack");
- }
-
- public void testStrLib() throws IOException, InterruptedException {
- runTest("strlib");
- }
-
- public void testSort() throws IOException, InterruptedException {
- runTest("sort");
- }
-
- public void testTable() throws IOException, InterruptedException {
- runTest("table");
- }
-
- public void testTailcall() throws IOException, InterruptedException {
- runTest("tailcall");
- }
-
- public void testType() throws IOException, InterruptedException {
- runTest("type");
- }
-
- public void testUpvalues() throws IOException, InterruptedException {
- runTest("upvalues");
- }
-
- public void testUpvalues2() throws IOException, InterruptedException {
- runTest("upvalues2");
- }
-
- public void testUpvalues3() throws IOException, InterruptedException {
- runTest("upvalues3");
- }
-
- public void testVarargs() throws IOException, InterruptedException {
- runTest("varargs");
- }
-
- public void testWeakTable() throws IOException, InterruptedException {
- runTest("weaktable");
- }
-}
diff --git a/src/test/java/org/luaj/vm/LuaJavaCoercionTest.java b/src/test/java/org/luaj/vm/LuaJavaCoercionTest.java
deleted file mode 100644
index 371d0149..00000000
--- a/src/test/java/org/luaj/vm/LuaJavaCoercionTest.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package org.luaj.vm;
-
-import junit.framework.TestCase;
-
-import org.luaj.lib.j2se.CoerceJavaToLua;
-import org.luaj.lib.j2se.CoerceLuaToJava;
-import org.luaj.platform.J2sePlatform;
-
-public class LuaJavaCoercionTest extends TestCase {
-
- private LuaState vm;
- private static LInteger ZERO = LInteger.valueOf(0);
- private static LInteger ONE = LInteger.valueOf(1);
- private static LInteger TWO = LInteger.valueOf(2);
- private static LInteger THREE = LInteger.valueOf(3);
- private static LString LENGTH = LString.valueOf("length");
-
- protected void setUp() throws Exception {
- super.setUp();
- Platform.setInstance( new J2sePlatform() );
- org.luaj.compiler.LuaC.install();
- vm = Platform.newLuaState();
- }
-
- public void testJavaIntToLuaInt() {
- Integer i = Integer.valueOf(777);
- LValue v = CoerceJavaToLua.coerce(i);
- assertEquals( LInteger.class, v.getClass() );
- assertEquals( 777, v.toJavaInt() );
- }
-
- public void testLuaIntToJavaInt() {
- LInteger i = LInteger.valueOf(777);
- Object o = CoerceLuaToJava.coerceArg(i, int.class);
- assertEquals( Integer.class, o.getClass() );
- assertEquals( 777, ((Number)o).intValue() );
- o = CoerceLuaToJava.coerceArg(i, Integer.class);
- assertEquals( Integer.class, o.getClass() );
- assertEquals( new Integer(777), o );
- }
-
- public void testJavaStringToLuaString() {
- String s = new String("777");
- LValue v = CoerceJavaToLua.coerce(s);
- assertEquals( LString.class, v.getClass() );
- assertEquals( "777", v.toJavaString() );
- }
-
- public void testLuaStringToJavaString() {
- LString s = new LString("777");
- Object o = CoerceLuaToJava.coerceArg(s, String.class);
- assertEquals( String.class, o.getClass() );
- assertEquals( "777", o );
- }
-
- public void testJavaIntArrayToLuaTable() {
- int[] i = { 222, 333 };
- LValue v = CoerceJavaToLua.coerce(i);
- assertEquals( LUserData.class, v.getClass() );
- assertNotNull( v.luaGetMetatable() );
- assertEquals( LInteger.valueOf(222), v.luaGetTable(vm, ONE) );
- assertEquals( LInteger.valueOf(333), v.luaGetTable(vm, TWO) );
- assertEquals( TWO, v.luaGetTable(vm, LENGTH));
- assertEquals( LNil.NIL, v.luaGetTable(vm, THREE) );
- assertEquals( LNil.NIL, v.luaGetTable(vm, ZERO) );
- v.luaSetTable(vm, ONE, LInteger.valueOf(444));
- v.luaSetTable(vm, TWO, LInteger.valueOf(555));
- assertEquals( 444, i[0] );
- assertEquals( 555, i[1] );
- assertEquals( LInteger.valueOf(444), v.luaGetTable(vm, ONE) );
- assertEquals( LInteger.valueOf(555), v.luaGetTable(vm, TWO) );
- try {
- v.luaSetTable(vm, ZERO, LInteger.valueOf(777));
- fail( "array bound exception not thrown" );
- } catch ( LuaErrorException lee ) {
- // expected
- }
- try {
- v.luaSetTable(vm, THREE, LInteger.valueOf(777));
- fail( "array bound exception not thrown" );
- } catch ( LuaErrorException lee ) {
- // expected
- }
- }
-
- public void testLuaTableToJavaIntArray() {
- LTable t = new LTable();
- t.put(1, LInteger.valueOf(222) );
- t.put(2, LInteger.valueOf(333) );
- int[] i = null;
- Object o = CoerceLuaToJava.coerceArg(t, int[].class);
- assertEquals( int[].class, o.getClass() );
- i = (int[]) o;
- assertEquals( 2, i.length );
- assertEquals( 222, i[0] );
- assertEquals( 333, i[1] );
- }
-
-
- public void testArrayParamScoring() {
- int a = 5;
- int[] b = { 44, 66 };
- int[][] c = { { 11, 22 }, { 33, 44 } };
- LValue la = LInteger.valueOf(a);
- LTable tb = new LTable();
- LTable tc = new LTable();
- LValue va = CoerceJavaToLua.coerce(a);
- LValue vb = CoerceJavaToLua.coerce(b);
- LValue vc = CoerceJavaToLua.coerce(c);
- tc.put( ONE, new LTable() );
-
- int saa = CoerceLuaToJava.scoreParamTypes( new LValue[] { la }, new Class[] { int.class } );
- int sab = CoerceLuaToJava.scoreParamTypes( new LValue[] { la }, new Class[] { int[].class } );
- int sac = CoerceLuaToJava.scoreParamTypes( new LValue[] { la }, new Class[] { int[][].class } );
- assertTrue( saa < sab );
- assertTrue( saa < sac );
- int sba = CoerceLuaToJava.scoreParamTypes( new LValue[] { tb }, new Class[] { int.class } );
- int sbb = CoerceLuaToJava.scoreParamTypes( new LValue[] { tb }, new Class[] { int[].class } );
- int sbc = CoerceLuaToJava.scoreParamTypes( new LValue[] { tb }, new Class[] { int[][].class } );
- assertTrue( sbb < sba );
- assertTrue( sbb < sbc );
- int sca = CoerceLuaToJava.scoreParamTypes( new LValue[] { tc }, new Class[] { int.class } );
- int scb = CoerceLuaToJava.scoreParamTypes( new LValue[] { tc }, new Class[] { int[].class } );
- int scc = CoerceLuaToJava.scoreParamTypes( new LValue[] { tc }, new Class[] { int[][].class } );
- assertTrue( scc < sca );
- assertTrue( scc < scb );
-
- int vaa = CoerceLuaToJava.scoreParamTypes( new LValue[] { va }, new Class[] { int.class } );
- int vab = CoerceLuaToJava.scoreParamTypes( new LValue[] { va }, new Class[] { int[].class } );
- int vac = CoerceLuaToJava.scoreParamTypes( new LValue[] { va }, new Class[] { int[][].class } );
- assertTrue( vaa < vab );
- assertTrue( vaa < vac );
- int vba = CoerceLuaToJava.scoreParamTypes( new LValue[] { vb }, new Class[] { int.class } );
- int vbb = CoerceLuaToJava.scoreParamTypes( new LValue[] { vb }, new Class[] { int[].class } );
- int vbc = CoerceLuaToJava.scoreParamTypes( new LValue[] { vb }, new Class[] { int[][].class } );
- assertTrue( vbb < vba );
- assertTrue( vbb < vbc );
- int vca = CoerceLuaToJava.scoreParamTypes( new LValue[] { vc }, new Class[] { int.class } );
- int vcb = CoerceLuaToJava.scoreParamTypes( new LValue[] { vc }, new Class[] { int[].class } );
- int vcc = CoerceLuaToJava.scoreParamTypes( new LValue[] { vc }, new Class[] { int[][].class } );
- assertTrue( vcc < vca );
- assertTrue( vcc < vcb );
- }
-
- public static class SampleClass {
- public String sample() { return "void-args"; }
- public String sample(int a) { return "int-args "+a; }
- public String sample(int[] a) { return "int-array-args "+a[0]+","+a[1]; }
- public String sample(int[][] a) { return "int-array-array-args "+a[0][0]+","+a[0][1]+","+a[1][0]+","+a[1][1]; }
- }
-
- private static final LString SAMPLE = LString.valueOf("sample");
-
- public void testIntArrayParameterMatching() {
- LValue v = CoerceJavaToLua.coerce(new SampleClass());
-
- // get sample field, call with no arguments
- LValue method = v.luaGetTable(vm, SAMPLE);
- vm.pushlvalue(method);
- vm.pushlvalue(v);
- vm.call(1,1);
- assertEquals( "void-args", vm.tostring(-1) );
-
- // get sample field, call with no arguments
- vm.pushlvalue(method);
- vm.pushlvalue(v);
- vm.pushlvalue( CoerceJavaToLua.coerce(new Integer(123)));
- vm.call(2,1);
- assertEquals( "int-args 123", vm.tostring(-1) );
-
- // get sample field, call with no arguments
- vm.pushlvalue(method);
- vm.pushlvalue(v);
- vm.pushlvalue( CoerceJavaToLua.coerce(new int[]{345,678}) );
- vm.call(2,1);
- assertEquals( "int-array-args 345,678", vm.tostring(-1) );
-
- // get sample field, call with no arguments
- vm.pushlvalue(method);
- vm.pushlvalue(v);
- vm.pushlvalue( CoerceJavaToLua.coerce(new int[][]{{22,33},{44,55}}) );
- vm.call(2,1);
- assertEquals( "int-array-array-args 22,33,44,55", vm.tostring(-1) );
- }
-
-
-}
diff --git a/test/junit/org/luaj/vm2/AllTests.java b/test/junit/org/luaj/vm2/AllTests.java
index f76f4283..52fa665a 100644
--- a/test/junit/org/luaj/vm2/AllTests.java
+++ b/test/junit/org/luaj/vm2/AllTests.java
@@ -27,6 +27,7 @@ import junit.framework.TestSuite;
import org.luaj.vm2.WeakTableTest.WeakKeyTableTest;
import org.luaj.vm2.WeakTableTest.WeakKeyValueTableTest;
import org.luaj.vm2.lib.jse.LuaJavaCoercionTest;
+import org.luaj.vm2.vm1.Luajvm1CompatibilityTest;
public class AllTests {
@@ -58,6 +59,7 @@ public class AllTests {
// compatiblity tests
suite.addTest(CompatibiltyTest.suite());
+ suite.addTestSuite(Luajvm1CompatibilityTest.class);
// luajc regression tests
TestSuite luajc = new TestSuite("Luajc Tests");
diff --git a/src/test/java/org/luaj/compiler/AbstractUnitTests.java b/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
similarity index 72%
rename from src/test/java/org/luaj/compiler/AbstractUnitTests.java
rename to test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
index 2785ea0c..95355070 100644
--- a/src/test/java/org/luaj/compiler/AbstractUnitTests.java
+++ b/test/junit/org/luaj/vm2/compiler/AbstractUnitTests.java
@@ -1,4 +1,4 @@
-package org.luaj.compiler;
+package org.luaj.vm2.compiler;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -9,42 +9,44 @@ import java.net.URL;
import junit.framework.TestCase;
-import org.luaj.TestPlatform;
-import org.luaj.vm.LPrototype;
-import org.luaj.vm.LoadState;
-import org.luaj.vm.LuaState;
-import org.luaj.vm.Platform;
-import org.luaj.vm.Print;
+import org.luaj.vm2.LoadState;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.Print;
+import org.luaj.vm2.Prototype;
+import org.luaj.vm2.lib.JsePlatform;
abstract public class AbstractUnitTests extends TestCase {
- private final String zipfile;
private final String dir;
+ private final String jar;
+ private LuaTable _G;
public AbstractUnitTests(String zipfile, String dir) {
- this.zipfile = zipfile;
+ URL zip = getClass().getResource(zipfile);
+ this.jar = "jar:" + zip.toExternalForm()+ "!/";
this.dir = dir;
}
protected void setUp() throws Exception {
super.setUp();
- Platform.setInstance(new TestPlatform());
+ _G = JsePlatform.standardGlobals();
+ LuaC.install();
}
protected void doTest(String file) {
try {
// load source from jar
- String path = "jar:file:" + zipfile + "!/" + dir + "/" + file;
+ String path = jar + dir + "/" + file;
byte[] lua = bytesFromJar(path);
// compile in memory
InputStream is = new ByteArrayInputStream(lua);
- LPrototype p = LuaC.compile(is, dir + "/" + file);
+ Prototype p = LuaC.compile(is, dir + "/" + file);
String actual = protoToString(p);
// load expected value from jar
byte[] luac = bytesFromJar(path + "c");
- LPrototype e = loadFromBytes(luac, file);
+ Prototype e = loadFromBytes(luac, file);
String expected = protoToString(e);
// compare results
@@ -56,7 +58,7 @@ abstract public class AbstractUnitTests extends TestCase {
byte[] dumped = baos.toByteArray();
// re-undump
- LPrototype p2 = loadFromBytes(dumped, file);
+ Prototype p2 = loadFromBytes(dumped, file);
String actual2 = protoToString(p2);
// compare again
@@ -79,14 +81,13 @@ abstract public class AbstractUnitTests extends TestCase {
return baos.toByteArray();
}
- protected LPrototype loadFromBytes(byte[] bytes, String script)
+ protected Prototype loadFromBytes(byte[] bytes, String script)
throws IOException {
- LuaState state = Platform.newLuaState();
InputStream is = new ByteArrayInputStream(bytes);
- return LoadState.undump(state, is, script);
+ return LoadState.compile(is, script);
}
- protected String protoToString(LPrototype p) {
+ protected String protoToString(Prototype p) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
Print.ps = ps;
diff --git a/src/test/java/org/luaj/compiler/CompilerUnitTests.java b/test/junit/org/luaj/vm2/compiler/CompilerUnitTests.java
similarity index 93%
rename from src/test/java/org/luaj/compiler/CompilerUnitTests.java
rename to test/junit/org/luaj/vm2/compiler/CompilerUnitTests.java
index 74abda2d..027b75b3 100644
--- a/src/test/java/org/luaj/compiler/CompilerUnitTests.java
+++ b/test/junit/org/luaj/vm2/compiler/CompilerUnitTests.java
@@ -1,11 +1,11 @@
-package org.luaj.compiler;
+package org.luaj.vm2.compiler;
public class CompilerUnitTests extends AbstractUnitTests {
public CompilerUnitTests() {
- super("src/test/compile/lua5.1-tests.zip", "lua5.1-tests");
+ super("lua5.1-tests.zip", "lua5.1-tests");
}
public void testAll() { doTest("all.lua"); }
diff --git a/src/test/java/org/luaj/compiler/DumpLoadEndianIntTest.java b/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
similarity index 89%
rename from src/test/java/org/luaj/compiler/DumpLoadEndianIntTest.java
rename to test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
index 1cde9ab4..5316bead 100644
--- a/src/test/java/org/luaj/compiler/DumpLoadEndianIntTest.java
+++ b/test/junit/org/luaj/vm2/compiler/DumpLoadEndianIntTest.java
@@ -1,4 +1,4 @@
-package org.luaj.compiler;
+package org.luaj.vm2.compiler;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -9,11 +9,13 @@ import java.io.InputStream;
import junit.framework.TestCase;
-import org.luaj.platform.J2sePlatform;
-import org.luaj.vm.LFunction;
-import org.luaj.vm.LPrototype;
-import org.luaj.vm.LuaState;
-import org.luaj.vm.Platform;
+import org.luaj.vm2.LoadState;
+import org.luaj.vm2.LuaClosure;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Prototype;
+import org.luaj.vm2.lib.JsePlatform;
+
public class DumpLoadEndianIntTest extends TestCase {
private static final String SAVECHUNKS = "SAVECHUNKS";
@@ -24,10 +26,13 @@ public class DumpLoadEndianIntTest extends TestCase {
private static final String intscript = "return tostring(1234)..'-#!-'..tostring(23)";
private static final String withdoubles = "1234-#!-23.75";
private static final String withints = "1234-#!-23";
-
+
+ private LuaTable _G;
+
protected void setUp() throws Exception {
super.setUp();
- Platform.setInstance(new J2sePlatform());
+ _G = JsePlatform.standardGlobals();
+ LuaC.install();
DumpState.ALLOW_INTEGER_CASTING = false;
}
@@ -76,17 +81,15 @@ public class DumpLoadEndianIntTest extends TestCase {
public void doTest( boolean littleEndian, int numberFormat, boolean stripDebug,
String script, String expectedPriorDump, String expectedPostDump, boolean shouldPass ) {
try {
- LuaState vm = Platform.newLuaState();
// compile into prototype
InputStream is = new ByteArrayInputStream(script.getBytes());
- LPrototype p = LuaC.compile(is, "script");
+ Prototype p = LuaC.compile(is, "script");
// double check script result before dumping
- LFunction f = p.newClosure(vm._G);
- vm.pushfunction(f);
- vm.call(0,1);
- String actual = vm.poplvalue().toJavaString();
+ LuaClosure f = new LuaClosure(p, _G);
+ LuaValue r = f.call();
+ String actual = r.toString();
assertEquals( expectedPriorDump, actual );
// dump into bytes
@@ -105,9 +108,10 @@ public class DumpLoadEndianIntTest extends TestCase {
// load again using compiler
is = new ByteArrayInputStream(dumped);
- vm.load(is, "dumped");
- vm.call(0,1);
- actual = vm.poplvalue().toJavaString();
+ p = LoadState.compile(is, "dumped");
+ f = new LuaClosure(p, _G);
+ r = f.call();
+ actual = r.toString();
assertEquals( expectedPostDump, actual );
// write test chunk
diff --git a/src/test/java/org/luaj/compiler/RegressionTests.java b/test/junit/org/luaj/vm2/compiler/RegressionTests.java
similarity index 93%
rename from src/test/java/org/luaj/compiler/RegressionTests.java
rename to test/junit/org/luaj/vm2/compiler/RegressionTests.java
index f36cc027..b6747965 100644
--- a/src/test/java/org/luaj/compiler/RegressionTests.java
+++ b/test/junit/org/luaj/vm2/compiler/RegressionTests.java
@@ -1,4 +1,4 @@
-package org.luaj.compiler;
+package org.luaj.vm2.compiler;
/**
* Framework to add regression tests as problem areas are found.
@@ -17,7 +17,7 @@ package org.luaj.compiler;
public class RegressionTests extends AbstractUnitTests {
public RegressionTests() {
- super( "src/test/compile/regressions.zip",
+ super( "regressions.zip",
"regressions" );
}
diff --git a/src/test/java/org/luaj/compiler/SimpleTests.java b/test/junit/org/luaj/vm2/compiler/SimpleTests.java
similarity index 71%
rename from src/test/java/org/luaj/compiler/SimpleTests.java
rename to test/junit/org/luaj/vm2/compiler/SimpleTests.java
index a20cb9d3..51440be4 100644
--- a/src/test/java/org/luaj/compiler/SimpleTests.java
+++ b/test/junit/org/luaj/vm2/compiler/SimpleTests.java
@@ -1,40 +1,40 @@
-package org.luaj.compiler;
+package org.luaj.vm2.compiler;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import junit.framework.TestCase;
-import org.luaj.TestPlatform;
-import org.luaj.lib.BaseLib;
-import org.luaj.vm.LClosure;
-import org.luaj.vm.LDouble;
-import org.luaj.vm.LInteger;
-import org.luaj.vm.LPrototype;
-import org.luaj.vm.LValue;
-import org.luaj.vm.LuaState;
-import org.luaj.vm.Platform;
-import org.luaj.vm.Print;
+import org.luaj.vm2.LuaClosure;
+import org.luaj.vm2.LuaDouble;
+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 {
+ private LuaTable _G;
+
protected void setUp() throws Exception {
super.setUp();
- Platform.setInstance(new TestPlatform());
+ _G = JsePlatform.standardGlobals();
+ LuaC.install();
}
private void doTest( String script ) {
try {
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
- LPrototype p = LuaC.compile( is, "script" );
+ Prototype p = LuaC.compile( is, "script" );
assertNotNull( p );
Print.printCode( p );
// try running the code!
- LuaState state = Platform.newLuaState();
- BaseLib.install( state._G );
- LClosure c = p.newClosure( state._G );
- state.doCall( c, new LValue[0] );
+ LuaClosure c = new LuaClosure( p, _G );
+ c.call();
} catch ( Exception e ) {
fail("i/o exception: "+e );
}
@@ -93,15 +93,15 @@ public class SimpleTests extends TestCase {
public void testDoubleHashCode() {
for ( int i=0; i