Add LuaValue.load() function for library initialization. Change unit tests to use JavaBytecodeCompiler for lua->Java conversion.

This commit is contained in:
James Roseborough
2010-04-03 03:48:53 +00:00
parent d903a85578
commit 46a9527701
7 changed files with 26 additions and 40 deletions

View File

@@ -56,7 +56,7 @@
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5"
classpath="build/core/classes;lib/bcel-5.2.jar"
srcdir="src/jse"
excludes="**/antlr/**,**/lst/**,**/JavaCodeGenerator.java" />
excludes="**/antlr/**,**/lst/**,**/JavaCodeGenerator.java,**/LuaJCompiler.java" />
</target>
<target name="jar-jme" depends="compile">
@@ -107,6 +107,7 @@
<exclude name="**/antlr/**"/>
<exclude name="**/lst/**"/>
<exclude name="**/JavaCodeGenerator.java"/>
<exclude name="**/LuaJCompiler.java"/>
</fileset>
</copy>
<copy todir="build/luaj-${version}/test">

View File

@@ -181,6 +181,7 @@ public class LuaValue extends Varargs {
public void presize( int i) { unimplemented("presize"); }
public Varargs next(LuaValue index) { unimplemented("next"); return null; }
public Varargs inext(LuaValue index) { unimplemented("inext"); return null; }
public LuaValue load(LuaValue library) { library.setfenv(this); return library.call(); }
// varargs references
public LuaValue arg(int index) { return index==1? this: NIL; }

View File

@@ -402,6 +402,4 @@ public class PackageLib extends OneArgFunction {
return false;
}
}
}

View File

@@ -23,11 +23,6 @@ package org.luaj.vm2.lib;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.lib.jme.JmeIoLib;
import org.luaj.vm2.lib.jse.JseBaseLib;
import org.luaj.vm2.lib.jse.JseIoLib;
import org.luaj.vm2.lib.jse.JseMathLib;
import org.luaj.vm2.lib.jse.JseOsLib;
import org.luaj.vm2.lib.jse.LuajavaLib;
public class JmePlatform {
@@ -38,23 +33,20 @@ public class JmePlatform {
*/
public static LuaTable standardGlobals() {
LuaTable _G = new LuaTable();
init(_G, new BaseLib());
init(_G, new PackageLib());
init(_G, new TableLib());
init(_G, new StringLib());
init(_G, new CoroutineLib());
init(_G, new JmeIoLib());
_G.load(new BaseLib());
_G.load(new PackageLib());
_G.load(new OsLib());
_G.load(new MathLib());
_G.load(new TableLib());
_G.load(new StringLib());
_G.load(new CoroutineLib());
_G.load(new JmeIoLib());
return _G;
}
public static LuaTable debugGlobals() {
LuaTable _G = standardGlobals();
init(_G, new DebugLib());
_G.load(new DebugLib());
return _G;
}
private static void init(LuaTable _G, LibFunction lib) {
lib.setfenv(_G);
lib.call();
}
}

View File

@@ -37,21 +37,16 @@ public class JsePlatform {
*/
public static LuaTable standardGlobals() {
LuaTable _G = new LuaTable();
init(_G, new JseBaseLib());
init(_G, new PackageLib());
init(_G, new TableLib());
init(_G, new StringLib());
init(_G, new CoroutineLib());
init(_G, new DebugLib());
init(_G, new JseMathLib());
init(_G, new JseIoLib());
init(_G, new JseOsLib());
init(_G, new LuajavaLib());
_G.load(new JseBaseLib());
_G.load(new PackageLib());
_G.load(new TableLib());
_G.load(new StringLib());
_G.load(new CoroutineLib());
_G.load(new DebugLib());
_G.load(new JseMathLib());
_G.load(new JseIoLib());
_G.load(new JseOsLib());
_G.load(new LuajavaLib());
return _G;
}
private static void init(LuaTable _G, LibFunction lib) {
lib.setfenv(_G);
lib.call();
}
}

View File

@@ -87,7 +87,7 @@ public class CompatibiltyTest {
}
public static class JseBytecodeTest extends CompatibiltyTestSuite {
public JseBytecodeTest() {
super(ScriptDrivenTest.PlatformType.JSE);
super(ScriptDrivenTest.PlatformType.LUAJIT);
}
protected void setUp() throws Exception {
super.setUp();

View File

@@ -32,8 +32,7 @@ import java.io.PrintStream;
import junit.framework.TestCase;
import org.luaj.vm2.lib.BaseLib;
import org.luaj.vm2.lib.DebugLib;
import org.luaj.vm2.luajc.LuaJCompiler;
import org.luaj.vm2.luajc.JavaBytecodeCompiler;
abstract
public class ScriptDrivenTest extends TestCase {
@@ -112,7 +111,7 @@ public class ScriptDrivenTest extends TestCase {
return c;
} else {
script = new FileInputStream(file);
return LuaJCompiler.compile( script, name, _G);
return JavaBytecodeCompiler.load( script, name, _G);
}
default:
script = new FileInputStream(file);