Changes made for the following:
1) Platform.java stays as abstract class with, but default implementation is removed. Stays in org.luaj.vm package
2) org.luaj.platform package is created to hold concrete Platform implementations
3) Platform.newLuaState() method is introduced to instantiate the LuaState. Other constructors are privatized.
4) Following Platform implementations are created:
J2sePlatform
J2meMidp20Cldc11Platform
J2meMidp10Cldc10Platform
5) All clients of luaj-vm are changed to include startup code that looks something like this:
Platform.setInstance( new J2meMidp20Cldc11Platform() );
LuaState state = Platform.getInstance().newLuaState();
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src/core"/>
|
<classpathentry kind="src" path="src/core"/>
|
||||||
|
<classpathentry kind="src" path="src/j2me"/>
|
||||||
<classpathentry kind="src" path="src/j2se"/>
|
<classpathentry kind="src" path="src/j2se"/>
|
||||||
<classpathentry kind="src" path="src/debug"/>
|
<classpathentry kind="src" path="src/debug"/>
|
||||||
<classpathentry kind="src" path="src/sample"/>
|
<classpathentry kind="src" path="src/sample"/>
|
||||||
|
|||||||
14
build.xml
14
build.xml
@@ -1,5 +1,5 @@
|
|||||||
<project default="all">
|
<project default="all">
|
||||||
<property name="version" value="0.14"/>
|
<property name="version" value="0.15"/>
|
||||||
|
|
||||||
<target name="clean">
|
<target name="clean">
|
||||||
<delete dir="build"/>
|
<delete dir="build"/>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<delete file="luaj-vm-${version}.jar"/>
|
<delete file="luaj-vm-${version}.jar"/>
|
||||||
<delete file="luaj-vm-core-${version}.jar"/>
|
<delete file="luaj-vm-core-${version}.jar"/>
|
||||||
<delete file="luaj-vm-extras-j2se-${version}.jar"/>
|
<delete file="luaj-vm-extras-j2se-${version}.jar"/>
|
||||||
<delete file="luaj-vm-debug-j2me-${version}.jar"/>
|
<delete file="luaj-vm-extras-j2me-${version}.jar"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile">
|
<target name="compile">
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
<javac destdir="build/all/classes" encoding="utf-8" source="1.3" target="1.1">
|
<javac destdir="build/all/classes" encoding="utf-8" source="1.3" target="1.1">
|
||||||
<src path="src/core" />
|
<src path="src/core" />
|
||||||
<src path="src/j2se" />
|
<src path="src/j2se" />
|
||||||
|
<exclude name="org/luaj/platform/**"/>
|
||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@
|
|||||||
<echo>Skipping steps that require J2ME WTK.</echo>
|
<echo>Skipping steps that require J2ME WTK.</echo>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="j2me-jars" depends="wtk-or-fail,jar-core,jar-j2se-extras,jar-j2me-debug"/>
|
<target name="j2me-jars" depends="wtk-or-fail,jar-core,jar-j2se-extras,jar-j2me-extra"/>
|
||||||
|
|
||||||
<target name="jar-core" depends="compile-core">
|
<target name="jar-core" depends="compile-core">
|
||||||
<jar destfile="luaj-vm-core-${version}.jar" basedir="build/core/classes"/>
|
<jar destfile="luaj-vm-core-${version}.jar" basedir="build/core/classes"/>
|
||||||
@@ -44,8 +45,8 @@
|
|||||||
<jar destfile="luaj-vm-extras-j2se-${version}.jar" basedir="build/extras-j2se/classes"/>
|
<jar destfile="luaj-vm-extras-j2se-${version}.jar" basedir="build/extras-j2se/classes"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar-j2me-debug" depends="compile-j2me-debug">
|
<target name="jar-j2me-extra" depends="compile-j2me-extra">
|
||||||
<jar destfile="luaj-vm-debug-j2me-${version}.jar" basedir="build/extras-j2me/classes"/>
|
<jar destfile="luaj-vm-extras-j2me-${version}.jar" basedir="build/extras-j2me/classes"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile-core" depends="wtk-or-fail">
|
<target name="compile-core" depends="wtk-or-fail">
|
||||||
@@ -73,10 +74,11 @@
|
|||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile-j2me-debug" depends="wtk-or-fail">
|
<target name="compile-j2me-extra" depends="wtk-or-fail">
|
||||||
<mkdir dir="build/extras-j2me/classes"/>
|
<mkdir dir="build/extras-j2me/classes"/>
|
||||||
<javac destdir="build/extras-j2me/classes" encoding="utf-8" source="1.3" target="1.1"
|
<javac destdir="build/extras-j2me/classes" encoding="utf-8" source="1.3" target="1.1"
|
||||||
bootclasspathref="wtk-libs" classpath="build/core/classes">
|
bootclasspathref="wtk-libs" classpath="build/core/classes">
|
||||||
|
<src path="src/j2me" />
|
||||||
<src path="src/debug" />
|
<src path="src/debug" />
|
||||||
<exclude name="org/luaj/debug/j2se/**"/>
|
<exclude name="org/luaj/debug/j2se/**"/>
|
||||||
<exclude name="org/luaj/debug/net/j2se/**"/>
|
<exclude name="org/luaj/debug/net/j2se/**"/>
|
||||||
|
|||||||
@@ -69,14 +69,6 @@ import org.luaj.lib.TableLib;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LuaState extends Lua {
|
public class LuaState extends Lua {
|
||||||
|
|
||||||
protected static final String DEBUG_CLASS_NAME = "org.luaj.debug.DebugLuaState";
|
|
||||||
|
|
||||||
public static final String PROPERTY_LUAJ_DEBUG = "Luaj-Debug";
|
|
||||||
public static final String PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START = "Luaj-Debug-SuspendAtStart";
|
|
||||||
public static final String PROPERTY_LUAJ_DEBUG_HOST = "Luaj-Debug-Host";
|
|
||||||
public static final String PROPERTY_LUAJ_DEBUG_PORT = "Luaj-Debug-Port";
|
|
||||||
|
|
||||||
/* thread status; 0 is OK */
|
/* thread status; 0 is OK */
|
||||||
private static final int LUA_YIELD = 1;
|
private static final int LUA_YIELD = 1;
|
||||||
private static final int LUA_ERRRUN = 2;
|
private static final int LUA_ERRRUN = 2;
|
||||||
@@ -117,10 +109,8 @@ public class LuaState extends Lua {
|
|||||||
* does all memory allocation for this state through this function. The
|
* does all memory allocation for this state through this function. The
|
||||||
* second argument, <code>ud</code>, is an opaque pointer that Lua simply
|
* second argument, <code>ud</code>, is an opaque pointer that Lua simply
|
||||||
* passes to the allocator in every call.
|
* passes to the allocator in every call.
|
||||||
*
|
|
||||||
* @deprecated As of version 0.10, replaced by {@link #newState()}
|
|
||||||
*/
|
*/
|
||||||
public LuaState() {
|
protected LuaState() {
|
||||||
_G = new LTable();
|
_G = new LTable();
|
||||||
_G.put("_G", _G);
|
_G.put("_G", _G);
|
||||||
mainState = this;
|
mainState = this;
|
||||||
@@ -135,33 +125,6 @@ public class LuaState extends Lua {
|
|||||||
_G = globals;
|
_G = globals;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method to return an instance of LuaState. If debug property is
|
|
||||||
* present, it will create a DebugLuaState instance.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static LuaState newState() {
|
|
||||||
String isDebugStr
|
|
||||||
= Platform.getInstance().getProperty(PROPERTY_LUAJ_DEBUG);
|
|
||||||
boolean isDebug = (isDebugStr != null && "true".equalsIgnoreCase(isDebugStr));
|
|
||||||
|
|
||||||
LuaState vm = null;
|
|
||||||
if ( isDebug ) {
|
|
||||||
try {
|
|
||||||
vm = (LuaState) Class.forName( DEBUG_CLASS_NAME ).newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Warning: no debug support, " + e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( vm == null )
|
|
||||||
vm = new LuaState();
|
|
||||||
|
|
||||||
vm.init();
|
|
||||||
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the initialization.
|
* Performs the initialization.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,16 +23,27 @@ package org.luaj.vm;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton to manage platform-specific behaviors.
|
* Singleton to manage platform-specific behaviors.
|
||||||
*
|
* <p>
|
||||||
* @deprecated - will probably be replaced with Config, LuaConfig or something
|
* Here is the sample code to set up the platform instance and create a new
|
||||||
* similar.
|
* LuaState instance.
|
||||||
|
* <pre>
|
||||||
|
* Platform.setInstance(new J2meMidp20Cldc11Platform());
|
||||||
|
* LuaState vm = Platform.newLuaState();
|
||||||
|
* </pre>
|
||||||
*/
|
*/
|
||||||
abstract public class Platform {
|
abstract public class Platform {
|
||||||
|
|
||||||
|
protected static final String DEBUG_CLASS_NAME = "org.luaj.debug.DebugLuaState";
|
||||||
|
|
||||||
|
public static final String PROPERTY_LUAJ_DEBUG = "Luaj-Debug";
|
||||||
|
public static final String PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START = "Luaj-Debug-SuspendAtStart";
|
||||||
|
public static final String PROPERTY_LUAJ_DEBUG_HOST = "Luaj-Debug-Host";
|
||||||
|
public static final String PROPERTY_LUAJ_DEBUG_PORT = "Luaj-Debug-Port";
|
||||||
|
|
||||||
private static Platform instance;
|
private static Platform instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,31 +54,9 @@ abstract public class Platform {
|
|||||||
*/
|
*/
|
||||||
public static Platform getInstance() {
|
public static Platform getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new Platform() {
|
throw new RuntimeException("Platform instance is null. Use Platform.setInstance(Platform p) to set the instance first.");
|
||||||
public Reader createReader(InputStream inputStream) {
|
|
||||||
return new InputStreamReader(inputStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream openFile(String fileName) {
|
|
||||||
return getClass().getResourceAsStream("/" + fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assumes J2SE platform, return the corresponding system
|
|
||||||
* property
|
|
||||||
*/
|
|
||||||
public String getProperty(String propertyName) {
|
|
||||||
return System.getProperty(propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a J2SE DebugSupport instance.
|
|
||||||
*/
|
|
||||||
public DebugNetSupport getDebugSupport() throws IOException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +70,35 @@ abstract public class Platform {
|
|||||||
instance = platform;
|
instance = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of LuaState. If debug properties are present,
|
||||||
|
* DebugLuaState (a LuaState with debugging capabilities) will be created.
|
||||||
|
*
|
||||||
|
* @return a new instance of LuaState
|
||||||
|
*/
|
||||||
|
public static LuaState newLuaState() {
|
||||||
|
Platform p = Platform.getInstance();
|
||||||
|
String isDebugStr = p.getProperty(PROPERTY_LUAJ_DEBUG);
|
||||||
|
boolean isDebug = (isDebugStr != null && "true".equalsIgnoreCase(isDebugStr));
|
||||||
|
|
||||||
|
LuaState vm = null;
|
||||||
|
if (isDebug) {
|
||||||
|
try {
|
||||||
|
vm = (LuaState) Class.forName(DEBUG_CLASS_NAME).newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Warning: no debug support, " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm == null)
|
||||||
|
vm = new LuaState();
|
||||||
|
|
||||||
|
vm.init();
|
||||||
|
p.installOptionalLibs(vm);
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an InputStream or null if not found for a particular file name.
|
* Return an InputStream or null if not found for a particular file name.
|
||||||
*
|
*
|
||||||
@@ -115,12 +133,26 @@ abstract public class Platform {
|
|||||||
*/
|
*/
|
||||||
abstract public DebugNetSupport getDebugSupport() throws IOException;
|
abstract public DebugNetSupport getDebugSupport() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install optional libraries on the LuaState.
|
||||||
|
* @param vm LuaState instance
|
||||||
|
*/
|
||||||
|
abstract protected void installOptionalLibs(LuaState vm);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute math.pow() for two numbers using double math when available.
|
||||||
|
* @param lhs LNumber base
|
||||||
|
* @param rhs LNumber exponent
|
||||||
|
* @return base ^ exponent as a LNumber, throw RuntimeException if not implemented
|
||||||
|
*/
|
||||||
|
abstract public LNumber mathPow(double lhs, double rhs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method for the subclasses to figure out the debug host.
|
* Convenience method for the subclasses to figure out the debug host.
|
||||||
* @return the debug host property. If it is not present, null is returned.
|
* @return the debug host property. If it is not present, null is returned.
|
||||||
*/
|
*/
|
||||||
protected String getDebugHost() {
|
protected String getDebugHost() {
|
||||||
String host = getProperty(LuaState.PROPERTY_LUAJ_DEBUG_HOST);
|
String host = getProperty(PROPERTY_LUAJ_DEBUG_HOST);
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +162,7 @@ abstract public class Platform {
|
|||||||
* as an integer if it is present in the platform properties and valid.
|
* as an integer if it is present in the platform properties and valid.
|
||||||
*/
|
*/
|
||||||
protected int getDebugPort() {
|
protected int getDebugPort() {
|
||||||
String portStr = getProperty(LuaState.PROPERTY_LUAJ_DEBUG_PORT);
|
String portStr = getProperty(PROPERTY_LUAJ_DEBUG_PORT);
|
||||||
int port = -1;
|
int port = -1;
|
||||||
if (portStr != null) {
|
if (portStr != null) {
|
||||||
try {
|
try {
|
||||||
@@ -139,14 +171,4 @@ abstract public class Platform {
|
|||||||
}
|
}
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute math.pow() for two numbers using double math when available.
|
|
||||||
* @param lhs LNumber base
|
|
||||||
* @param rhs LNumber exponent
|
|
||||||
* @return base ^ exponent as a LNumber, or null if not implemented
|
|
||||||
*/
|
|
||||||
public LNumber mathPow(double lhs, double rhs) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
/**
|
/**
|
||||||
* Creates an instance of DebugLuaState.
|
* Creates an instance of DebugLuaState.
|
||||||
*
|
*
|
||||||
* @deprecated As of version 0.10, replaced by {@link #LuaState.newState()}
|
* @deprecated As of version 0.10, replaced by {@link #Platform.newLuaState()}
|
||||||
*/
|
*/
|
||||||
public DebugLuaState() {}
|
public DebugLuaState() {}
|
||||||
|
|
||||||
@@ -185,10 +185,12 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
* @see org.luaj.vm.LuaState#init()
|
* @see org.luaj.vm.LuaState#init()
|
||||||
*/
|
*/
|
||||||
public void init() {
|
public void init() {
|
||||||
|
super.init();
|
||||||
|
|
||||||
Platform platform = Platform.getInstance();
|
Platform platform = Platform.getInstance();
|
||||||
|
|
||||||
// set if the vm should be suspended at start
|
// set if the vm should be suspended at start
|
||||||
String suspendOnStartStr = platform.getProperty(PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START);
|
String suspendOnStartStr = platform.getProperty(Platform.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START);
|
||||||
boolean bSuspendOnStart = (suspendOnStartStr != null && "true".equalsIgnoreCase(suspendOnStartStr));
|
boolean bSuspendOnStart = (suspendOnStartStr != null && "true".equalsIgnoreCase(suspendOnStartStr));
|
||||||
setSuspendAtStart(bSuspendOnStart);
|
setSuspendAtStart(bSuspendOnStart);
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package org.luaj.debug.j2se;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
|
|
||||||
import org.luaj.debug.net.j2se.DebugSupportImpl;
|
|
||||||
import org.luaj.vm.DebugNetSupport;
|
|
||||||
import org.luaj.vm.Platform;
|
|
||||||
|
|
||||||
public class J2sePlatform extends Platform {
|
|
||||||
public Reader createReader(InputStream inputStream) {
|
|
||||||
return new InputStreamReader(inputStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream openFile(String filePath) {
|
|
||||||
try {
|
|
||||||
FileInputStream fis = new FileInputStream(new File(filePath));
|
|
||||||
return fis;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assumes J2SE platform, return the corresponding system
|
|
||||||
* property
|
|
||||||
*/
|
|
||||||
public String getProperty(String propertyName) {
|
|
||||||
return System.getProperty(propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a J2SE DebugSupport instance.
|
|
||||||
*/
|
|
||||||
public DebugNetSupport getDebugSupport() throws IOException {
|
|
||||||
int port = getDebugPort();
|
|
||||||
DebugSupportImpl debugSupport = new DebugSupportImpl(port);
|
|
||||||
return debugSupport;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,7 +29,7 @@ import java.io.InputStream;
|
|||||||
import org.luaj.compiler.LuaC;
|
import org.luaj.compiler.LuaC;
|
||||||
import org.luaj.debug.DebugLuaState;
|
import org.luaj.debug.DebugLuaState;
|
||||||
import org.luaj.lib.PackageLib;
|
import org.luaj.lib.PackageLib;
|
||||||
import org.luaj.lib.j2se.LuajavaLib;
|
import org.luaj.platform.J2sePlatform;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LString;
|
import org.luaj.vm.LString;
|
||||||
@@ -84,7 +84,7 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isDebugMode = true;
|
this.isDebugMode = true;
|
||||||
System.setProperty(LuaState.PROPERTY_LUAJ_DEBUG, "true");
|
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG, "true");
|
||||||
|
|
||||||
String debugOptions = args[index];
|
String debugOptions = args[index];
|
||||||
debugOptions = debugOptions.substring(2); // remove '-D'
|
debugOptions = debugOptions.substring(2); // remove '-D'
|
||||||
@@ -94,7 +94,7 @@ public class StandardLuaJVM {
|
|||||||
String portString = options[i].substring(CMD_LINE_DEBUG_OPTION_PORT.length());
|
String portString = options[i].substring(CMD_LINE_DEBUG_OPTION_PORT.length());
|
||||||
try {
|
try {
|
||||||
this.debugPort = Integer.parseInt(portString);
|
this.debugPort = Integer.parseInt(portString);
|
||||||
System.setProperty(DebugLuaState.PROPERTY_LUAJ_DEBUG_PORT, String.valueOf(debugPort));
|
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG_PORT, String.valueOf(debugPort));
|
||||||
if (this.debugPort <= 0) {
|
if (this.debugPort <= 0) {
|
||||||
throw new ParseException(
|
throw new ParseException(
|
||||||
"Invalid debug port: it must be greater than zero.");
|
"Invalid debug port: it must be greater than zero.");
|
||||||
@@ -110,7 +110,7 @@ public class StandardLuaJVM {
|
|||||||
throw new ParseException("invalid debug flag: suspendOnStart");
|
throw new ParseException("invalid debug flag: suspendOnStart");
|
||||||
}
|
}
|
||||||
this.bSuspendOnStart = Boolean.parseBoolean(suspendOnStartStr);
|
this.bSuspendOnStart = Boolean.parseBoolean(suspendOnStartStr);
|
||||||
System.setProperty(DebugLuaState.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START, suspendOnStartStr);
|
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START, suspendOnStartStr);
|
||||||
} else {
|
} else {
|
||||||
throw new ParseException("Invalid command line argument: " + debugOptions);
|
throw new ParseException("Invalid command line argument: " + debugOptions);
|
||||||
}
|
}
|
||||||
@@ -185,8 +185,7 @@ public class StandardLuaJVM {
|
|||||||
try {
|
try {
|
||||||
// new lua debug state
|
// new lua debug state
|
||||||
Platform.setInstance(new J2sePlatform());
|
Platform.setInstance(new J2sePlatform());
|
||||||
|
state = Platform.newLuaState();
|
||||||
state = LuaState.newState();
|
|
||||||
init(state);
|
init(state);
|
||||||
|
|
||||||
// load the Lua file
|
// load the Lua file
|
||||||
@@ -218,13 +217,6 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void init(LuaState state) {
|
protected void init(LuaState state) {
|
||||||
|
|
||||||
// add standard bindings
|
|
||||||
state.installStandardLibs();
|
|
||||||
|
|
||||||
// add LuaJava bindings
|
|
||||||
LuajavaLib.install(state._G);
|
|
||||||
|
|
||||||
// add the compiler
|
// add the compiler
|
||||||
LuaC.install();
|
LuaC.install();
|
||||||
|
|
||||||
|
|||||||
51
src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java
Normal file
51
src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package org.luaj.platform;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
|
import javax.microedition.midlet.MIDlet;
|
||||||
|
|
||||||
|
import org.luaj.debug.net.j2me.DebugSupportImpl;
|
||||||
|
import org.luaj.vm.DebugNetSupport;
|
||||||
|
import org.luaj.vm.LNumber;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
public class J2meMidp10Cldc10Platform extends Platform {
|
||||||
|
protected MIDlet midlet;
|
||||||
|
|
||||||
|
public J2meMidp10Cldc10Platform(MIDlet midlet) {
|
||||||
|
this.midlet = midlet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reader createReader(InputStream inputStream) {
|
||||||
|
return new InputStreamReader(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream openFile(String fileName) {
|
||||||
|
if (!fileName.startsWith("/"))
|
||||||
|
fileName = "/" + fileName;
|
||||||
|
InputStream is = this.getClass().getResourceAsStream(fileName);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DebugNetSupport getDebugSupport() throws IOException {
|
||||||
|
String host = getDebugHost();
|
||||||
|
int port = getDebugPort();
|
||||||
|
return new DebugSupportImpl(host, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String key) {
|
||||||
|
return midlet.getAppProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void installOptionalLibs(LuaState vm) {
|
||||||
|
vm.installStandardLibs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LNumber mathPow(double lhs, double rhs) {
|
||||||
|
throw new RuntimeException("mathPow(double lhs, double rhs) is not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/j2me/org/luaj/platform/J2meMidp20Cldc11Platform.java
Normal file
9
src/j2me/org/luaj/platform/J2meMidp20Cldc11Platform.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package org.luaj.platform;
|
||||||
|
|
||||||
|
import javax.microedition.midlet.MIDlet;
|
||||||
|
|
||||||
|
public class J2meMidp20Cldc11Platform extends J2meMidp10Cldc10Platform {
|
||||||
|
public J2meMidp20Cldc11Platform(MIDlet midlet) {
|
||||||
|
super(midlet);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/j2se/org/luaj/platform/J2sePlatform.java
Normal file
51
src/j2se/org/luaj/platform/J2sePlatform.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package org.luaj.platform;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
|
import org.luaj.debug.net.j2se.DebugSupportImpl;
|
||||||
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
|
import org.luaj.vm.DebugNetSupport;
|
||||||
|
import org.luaj.vm.LDouble;
|
||||||
|
import org.luaj.vm.LNumber;
|
||||||
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
public class J2sePlatform extends Platform {
|
||||||
|
public Reader createReader(InputStream inputStream) {
|
||||||
|
return new InputStreamReader(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DebugNetSupport getDebugSupport() throws IOException {
|
||||||
|
DebugNetSupport debugNetSupport = new DebugSupportImpl(getDebugPort());
|
||||||
|
return debugNetSupport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String propertyName) {
|
||||||
|
return System.getProperty(propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void installOptionalLibs(LuaState vm) {
|
||||||
|
vm.installStandardLibs();
|
||||||
|
LuajavaLib.install(vm._G);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream openFile(String fileName) {
|
||||||
|
File file = new File(fileName);
|
||||||
|
try {
|
||||||
|
return new FileInputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LNumber mathPow(double lhs, double rhs) {
|
||||||
|
double d = Math.pow(lhs, rhs);
|
||||||
|
return LDouble.valueOf(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,12 +27,14 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.luaj.compiler.LuaC;
|
import org.luaj.compiler.LuaC;
|
||||||
|
import org.luaj.platform.J2sePlatform;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LValue;
|
import org.luaj.vm.LValue;
|
||||||
import org.luaj.vm.LoadState;
|
import org.luaj.vm.LoadState;
|
||||||
import org.luaj.vm.LuaErrorException;
|
import org.luaj.vm.LuaErrorException;
|
||||||
import org.luaj.vm.LuaState;
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +47,9 @@ public class LuaRunner {
|
|||||||
public static void main( String[] args ) throws IOException {
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
// new lua state
|
// new lua state
|
||||||
LuaState state = LuaState.newState();
|
Platform.setInstance(new J2sePlatform());
|
||||||
|
LuaState state = Platform.newLuaState();
|
||||||
|
LuaC.install();
|
||||||
|
|
||||||
// get script name
|
// get script name
|
||||||
for ( int i=0; i<args.length; i++ ) {
|
for ( int i=0; i<args.length; i++ ) {
|
||||||
@@ -53,10 +57,6 @@ public class LuaRunner {
|
|||||||
try {
|
try {
|
||||||
System.out.println("loading '"+script+"'");
|
System.out.println("loading '"+script+"'");
|
||||||
|
|
||||||
// add standard bindings
|
|
||||||
state.installStandardLibs();
|
|
||||||
LuaC.install();
|
|
||||||
|
|
||||||
// load the file
|
// load the file
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
File f = new File(script);
|
File f = new File(script);
|
||||||
|
|||||||
@@ -24,18 +24,14 @@ package org.luaj.sample;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.luaj.lib.CoroutineLib;
|
|
||||||
import org.luaj.lib.MathLib;
|
|
||||||
import org.luaj.lib.PackageLib;
|
|
||||||
import org.luaj.lib.StringLib;
|
|
||||||
import org.luaj.lib.TableLib;
|
|
||||||
import org.luaj.lib.j2se.LuajavaLib;
|
import org.luaj.lib.j2se.LuajavaLib;
|
||||||
|
import org.luaj.platform.J2sePlatform;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LTable;
|
|
||||||
import org.luaj.vm.LValue;
|
import org.luaj.vm.LValue;
|
||||||
import org.luaj.vm.LoadState;
|
import org.luaj.vm.LoadState;
|
||||||
import org.luaj.vm.LuaState;
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,14 +44,10 @@ public class LuajavaRunner {
|
|||||||
|
|
||||||
public static void main( String[] args ) throws IOException {
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
|
Platform.setInstance(new J2sePlatform());
|
||||||
|
|
||||||
// new lua state
|
// new lua state
|
||||||
LuaState state = new LuaState();
|
LuaState state = Platform.newLuaState();
|
||||||
|
|
||||||
// add standard bindings
|
|
||||||
state.installStandardLibs();
|
|
||||||
|
|
||||||
// add LuaJava bindings
|
|
||||||
LuajavaLib.install(state._G);
|
|
||||||
|
|
||||||
// get script name
|
// get script name
|
||||||
String script = (args.length>0? args[0]: "/swingapp.luac");
|
String script = (args.length>0? args[0]: "/swingapp.luac");
|
||||||
|
|||||||
11
src/test/java/org/luaj/TestPlatform.java
Normal file
11
src/test/java/org/luaj/TestPlatform.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package org.luaj;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.luaj.platform.J2sePlatform;
|
||||||
|
|
||||||
|
public class TestPlatform extends J2sePlatform {
|
||||||
|
public InputStream openFile(String fileName) {
|
||||||
|
return getClass().getResourceAsStream("/" + fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,14 +9,14 @@ import java.net.URL;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.luaj.TestPlatform;
|
||||||
import org.luaj.debug.Print;
|
import org.luaj.debug.Print;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LoadState;
|
import org.luaj.vm.LoadState;
|
||||||
import org.luaj.vm.LuaState;
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
abstract public class AbstractUnitTests extends TestCase {
|
||||||
abstract
|
|
||||||
public class AbstractUnitTests extends TestCase {
|
|
||||||
|
|
||||||
private final String zipfile;
|
private final String zipfile;
|
||||||
private final String dir;
|
private final String dir;
|
||||||
@@ -26,24 +26,29 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doTest( String file ) {
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
Platform.setInstance(new TestPlatform());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTest(String file) {
|
||||||
try {
|
try {
|
||||||
// load source from jar
|
// load source from jar
|
||||||
String path = "jar:file:" + zipfile + "!/" + dir + "/" + file;
|
String path = "jar:file:" + zipfile + "!/" + dir + "/" + file;
|
||||||
byte[] lua = bytesFromJar( path );
|
byte[] lua = bytesFromJar(path);
|
||||||
|
|
||||||
// compile in memory
|
// compile in memory
|
||||||
InputStream is = new ByteArrayInputStream( lua );
|
InputStream is = new ByteArrayInputStream(lua);
|
||||||
LPrototype p = LuaC.compile(is, dir+"/"+file);
|
LPrototype p = LuaC.compile(is, dir + "/" + file);
|
||||||
String actual = protoToString( p );
|
String actual = protoToString(p);
|
||||||
|
|
||||||
// load expected value from jar
|
// load expected value from jar
|
||||||
byte[] luac = bytesFromJar( path + "c" );
|
byte[] luac = bytesFromJar(path + "c");
|
||||||
LPrototype e = loadFromBytes( luac, file );
|
LPrototype e = loadFromBytes(luac, file);
|
||||||
String expected = protoToString( e );
|
String expected = protoToString(e);
|
||||||
|
|
||||||
// compare results
|
// compare results
|
||||||
assertEquals( expected, actual );
|
assertEquals(expected, actual);
|
||||||
|
|
||||||
// dump into memory
|
// dump into memory
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
@@ -51,14 +56,14 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
byte[] dumped = baos.toByteArray();
|
byte[] dumped = baos.toByteArray();
|
||||||
|
|
||||||
// re-undump
|
// re-undump
|
||||||
LPrototype p2 = loadFromBytes( dumped, file );
|
LPrototype p2 = loadFromBytes(dumped, file);
|
||||||
String actual2 = protoToString( p2 );
|
String actual2 = protoToString(p2);
|
||||||
|
|
||||||
// compare again
|
// compare again
|
||||||
assertEquals( actual, actual2 );
|
assertEquals(actual, actual2);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail( e.toString() );
|
fail(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,25 +73,25 @@ public class AbstractUnitTests extends TestCase {
|
|||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
byte[] buffer = new byte[2048];
|
byte[] buffer = new byte[2048];
|
||||||
int n;
|
int n;
|
||||||
while ( (n = is.read(buffer)) >= 0 )
|
while ((n = is.read(buffer)) >= 0)
|
||||||
baos.write( buffer, 0, n );
|
baos.write(buffer, 0, n);
|
||||||
is.close();
|
is.close();
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LPrototype loadFromBytes(byte[] bytes, String script) throws IOException {
|
protected LPrototype loadFromBytes(byte[] bytes, String script)
|
||||||
LuaState state = new LuaState();
|
throws IOException {
|
||||||
InputStream is = new ByteArrayInputStream( bytes );
|
LuaState state = Platform.newLuaState();
|
||||||
|
InputStream is = new ByteArrayInputStream(bytes);
|
||||||
return LoadState.undump(state, is, script);
|
return LoadState.undump(state, is, script);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String protoToString(LPrototype p) {
|
protected String protoToString(LPrototype p) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintStream ps = new PrintStream( baos );
|
PrintStream ps = new PrintStream(baos);
|
||||||
Print.ps = ps;
|
Print.ps = ps;
|
||||||
new Print().printFunction(p, true);
|
new Print().printFunction(p, true);
|
||||||
return baos.toString();
|
return baos.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,11 @@
|
|||||||
package org.luaj.compiler;
|
package org.luaj.compiler;
|
||||||
|
|
||||||
import org.luaj.debug.j2se.J2sePlatform;
|
|
||||||
import org.luaj.vm.LDouble;
|
|
||||||
import org.luaj.vm.LNumber;
|
|
||||||
import org.luaj.vm.Platform;
|
|
||||||
|
|
||||||
|
|
||||||
public class CompilerUnitTests extends AbstractUnitTests {
|
public class CompilerUnitTests extends AbstractUnitTests {
|
||||||
|
|
||||||
static {
|
|
||||||
// override platform to test with standard debug features.
|
|
||||||
Platform.setInstance( new J2sePlatform() {
|
|
||||||
public LNumber mathPow(double lhs, double rhs) {
|
|
||||||
double d = Math.pow(lhs, rhs);
|
|
||||||
return LDouble.valueOf(d);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompilerUnitTests() {
|
public CompilerUnitTests() {
|
||||||
super( "src/test/compile/lua5.1-tests.zip",
|
super("src/test/compile/lua5.1-tests.zip", "lua5.1-tests");
|
||||||
"lua5.1-tests" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAll() { doTest("all.lua"); }
|
public void testAll() { doTest("all.lua"); }
|
||||||
|
|||||||
@@ -5,15 +5,22 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.luaj.TestPlatform;
|
||||||
import org.luaj.debug.Print;
|
import org.luaj.debug.Print;
|
||||||
import org.luaj.lib.BaseLib;
|
import org.luaj.lib.BaseLib;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LValue;
|
import org.luaj.vm.LValue;
|
||||||
import org.luaj.vm.LuaState;
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
public class SimpleTests extends TestCase {
|
public class SimpleTests extends TestCase {
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
Platform.setInstance(new TestPlatform());
|
||||||
|
}
|
||||||
|
|
||||||
private void doTest( String script ) {
|
private void doTest( String script ) {
|
||||||
try {
|
try {
|
||||||
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
||||||
@@ -22,7 +29,7 @@ public class SimpleTests extends TestCase {
|
|||||||
Print.printCode( p );
|
Print.printCode( p );
|
||||||
|
|
||||||
// try running the code!
|
// try running the code!
|
||||||
LuaState state = new LuaState();
|
LuaState state = Platform.newLuaState();
|
||||||
BaseLib.install( state._G );
|
BaseLib.install( state._G );
|
||||||
LClosure c = new LClosure( state, p );
|
LClosure c = new LClosure( state, p );
|
||||||
state.doCall( c, new LValue[0] );
|
state.doCall( c, new LValue[0] );
|
||||||
|
|||||||
@@ -24,21 +24,33 @@ package org.luaj.debug;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.luaj.debug.DebugLuaState;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.luaj.TestPlatform;
|
||||||
|
import org.luaj.compiler.LuaC;
|
||||||
|
import org.luaj.vm.DebugNetSupport;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
|
import org.luaj.vm.LPrototype;
|
||||||
import org.luaj.vm.LValue;
|
import org.luaj.vm.LValue;
|
||||||
import org.luaj.vm.LoadState;
|
import org.luaj.vm.LoadState;
|
||||||
import org.luaj.vm.LPrototype;
|
import org.luaj.vm.LuaState;
|
||||||
|
import org.luaj.vm.Platform;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class DebugStackStateTest extends TestCase {
|
public class DebugStackStateTest extends TestCase {
|
||||||
|
|
||||||
public void testDebugStackState() throws InterruptedException, IOException {
|
public void testDebugStackState() throws InterruptedException, IOException {
|
||||||
String script = "/test6.luac";
|
String script = "/test6.lua";
|
||||||
|
|
||||||
// set up the vm
|
// set up the vm
|
||||||
final DebugLuaState state = new DebugLuaState();
|
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG, "true");
|
||||||
|
Platform.setInstance(new TestPlatform() {
|
||||||
|
public DebugNetSupport getDebugSupport() throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final DebugLuaState state = (DebugLuaState) Platform.newLuaState();
|
||||||
|
LuaC.install();
|
||||||
InputStream is = getClass().getResourceAsStream( script );
|
InputStream is = getClass().getResourceAsStream( script );
|
||||||
LPrototype p = LoadState.undump(state, is, script);
|
LPrototype p = LoadState.undump(state, is, script);
|
||||||
|
|
||||||
|
|||||||
@@ -21,20 +21,13 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.luaj.debug.DebugLuaState;
|
import org.luaj.TestPlatform;
|
||||||
import org.luaj.debug.j2se.StandardLuaJVM.ParseException;
|
import org.luaj.debug.j2se.StandardLuaJVM.ParseException;
|
||||||
import org.luaj.debug.net.j2se.DebugSupportImpl;
|
|
||||||
import org.luaj.vm.DebugNetSupport;
|
|
||||||
import org.luaj.vm.LuaState;
|
|
||||||
import org.luaj.vm.Platform;
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,33 +37,8 @@ public class LuaJVMTest extends TestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
System.setProperty(DebugLuaState.PROPERTY_LUAJ_DEBUG_PORT, "1999");
|
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG_PORT, "1999");
|
||||||
|
Platform.setInstance(new TestPlatform());
|
||||||
Platform.setInstance(new Platform() {
|
|
||||||
public Reader createReader(InputStream inputStream) {
|
|
||||||
return new InputStreamReader(inputStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream openFile(String fileName) {
|
|
||||||
return getClass().getResourceAsStream("/" + fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assumes J2SE platform, return the corresponding system property
|
|
||||||
*/
|
|
||||||
public String getProperty(String propertyName) {
|
|
||||||
return System.getProperty(propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a J2SE DebugSupport instance.
|
|
||||||
*/
|
|
||||||
public DebugNetSupport getDebugSupport() throws IOException {
|
|
||||||
int port = getDebugPort();
|
|
||||||
DebugSupportImpl debugSupport = new DebugSupportImpl(port);
|
|
||||||
return debugSupport;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommandLineParse() {
|
public void testCommandLineParse() {
|
||||||
@@ -244,10 +212,10 @@ public class LuaJVMTest extends TestCase {
|
|||||||
|
|
||||||
public void testRun() {
|
public void testRun() {
|
||||||
Properties props = System.getProperties();
|
Properties props = System.getProperties();
|
||||||
props.remove(LuaState.PROPERTY_LUAJ_DEBUG);
|
props.remove(Platform.PROPERTY_LUAJ_DEBUG);
|
||||||
props.remove(DebugLuaState.PROPERTY_LUAJ_DEBUG_HOST);
|
props.remove(Platform.PROPERTY_LUAJ_DEBUG_HOST);
|
||||||
props.remove(DebugLuaState.PROPERTY_LUAJ_DEBUG_PORT);
|
props.remove(Platform.PROPERTY_LUAJ_DEBUG_PORT);
|
||||||
props.remove(DebugLuaState.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START);
|
props.remove(Platform.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START);
|
||||||
System.setProperties(props);
|
System.setProperties(props);
|
||||||
|
|
||||||
String[] tests = new String[] { "autoload", "boolean", "calls",
|
String[] tests = new String[] { "autoload", "boolean", "calls",
|
||||||
@@ -261,8 +229,8 @@ public class LuaJVMTest extends TestCase {
|
|||||||
|
|
||||||
public void testDebugRun() {
|
public void testDebugRun() {
|
||||||
Properties props = System.getProperties();
|
Properties props = System.getProperties();
|
||||||
props.setProperty(LuaState.PROPERTY_LUAJ_DEBUG, "true");
|
props.setProperty(Platform.PROPERTY_LUAJ_DEBUG, "true");
|
||||||
props.setProperty(DebugLuaState.PROPERTY_LUAJ_DEBUG_PORT, "1999");
|
props.setProperty(Platform.PROPERTY_LUAJ_DEBUG_PORT, "1999");
|
||||||
System.setProperties(props);
|
System.setProperties(props);
|
||||||
|
|
||||||
String[] tests = new String[] { "boolean", "calls",
|
String[] tests = new String[] { "boolean", "calls",
|
||||||
|
|||||||
@@ -6,14 +6,19 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.luaj.TestPlatform;
|
||||||
import org.luaj.compiler.LuaC;
|
import org.luaj.compiler.LuaC;
|
||||||
import org.luaj.debug.DebugLuaState;
|
|
||||||
import org.luaj.lib.BaseLib;
|
import org.luaj.lib.BaseLib;
|
||||||
import org.luaj.lib.j2se.LuajavaLib;
|
|
||||||
|
|
||||||
|
|
||||||
public class LuaJTest extends TestCase {
|
public class LuaJTest extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
Platform.setInstance(new TestPlatform());
|
||||||
|
}
|
||||||
|
|
||||||
public void testTest1() throws IOException, InterruptedException {
|
public void testTest1() throws IOException, InterruptedException {
|
||||||
runTest( "test1" );
|
runTest( "test1" );
|
||||||
}
|
}
|
||||||
@@ -149,13 +154,9 @@ public class LuaJTest extends TestCase {
|
|||||||
private void runTest( String testName ) throws IOException, InterruptedException {
|
private void runTest( String testName ) throws IOException, InterruptedException {
|
||||||
|
|
||||||
// new lua state
|
// new lua state
|
||||||
LuaState state = LuaState.newState();
|
LuaState state = Platform.newLuaState();
|
||||||
|
|
||||||
// add standard bindings
|
// install the compiler
|
||||||
state.installStandardLibs();
|
|
||||||
|
|
||||||
// add luajava
|
|
||||||
LuajavaLib.install( state._G );
|
|
||||||
LuaC.install();
|
LuaC.install();
|
||||||
|
|
||||||
// load the file
|
// load the file
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import junit.framework.Test;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.luaj.debug.DebugLuaState;
|
import org.luaj.TestPlatform;
|
||||||
import org.luaj.lib.BaseLib;
|
import org.luaj.lib.BaseLib;
|
||||||
|
|
||||||
public class StandardTest extends TestCase {
|
public class StandardTest extends TestCase {
|
||||||
@@ -65,10 +65,8 @@ public class StandardTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
LuaState state = new DebugLuaState();
|
Platform.setInstance(new TestPlatform());
|
||||||
|
LuaState state = Platform.newLuaState();
|
||||||
// add standard bindings
|
|
||||||
state.installStandardLibs();
|
|
||||||
|
|
||||||
// hack: it's unpleasant when the test cases fail to terminate;
|
// hack: it's unpleasant when the test cases fail to terminate;
|
||||||
// unfortunately, there is a test in the standard suite that
|
// unfortunately, there is a test in the standard suite that
|
||||||
|
|||||||
Reference in New Issue
Block a user