1. added a shutdown method for LuaState and DebugLuaState to clean up before shutting down
2. added the capability to set LUA_PATH 3. minor debugging improvement 4. bump up the version to 0.12 because the addition outputRedirect debug message is not compatible with the previous versions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<project default="all">
|
||||
<property name="version" value="0.11"/>
|
||||
<property name="version" value="0.12"/>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="build"/>
|
||||
|
||||
@@ -167,6 +167,11 @@ public class LuaState extends Lua {
|
||||
*/
|
||||
public void init() {}
|
||||
|
||||
/**
|
||||
* Perform any shutdown/clean up tasks if needed
|
||||
*/
|
||||
public void shutdown() {}
|
||||
|
||||
/**
|
||||
* Install the standard set of libraries used by most implementations:
|
||||
* BaseLib, CoroutineLib, MathLib, PackageLib, TableLib, StringLib
|
||||
|
||||
@@ -77,7 +77,11 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||
*/
|
||||
public DebugLuaState() {}
|
||||
|
||||
public void init() {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.luaj.vm.LuaState#init()
|
||||
*/
|
||||
public void init() {
|
||||
Platform platform = Platform.getInstance();
|
||||
|
||||
// set if the vm should be suspended at start
|
||||
@@ -98,6 +102,14 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.luaj.vm.LuaState#shutdown()
|
||||
*/
|
||||
public void shutdown() {
|
||||
stop();
|
||||
}
|
||||
|
||||
protected void setDebugSupport(DebugNetSupport debugSupport)
|
||||
throws IOException {
|
||||
if (debugSupport == null) {
|
||||
|
||||
@@ -52,17 +52,16 @@ public class DebugMessageType extends EnumType {
|
||||
public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 20);
|
||||
public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 21);
|
||||
public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 22);
|
||||
public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 23);
|
||||
public static final DebugMessageType resumedOnError = new DebugMessageType("resumedOnError", 24);
|
||||
public static final DebugMessageType error = new DebugMessageType("error", 25);
|
||||
public static final DebugMessageType terminated = new DebugMessageType("terminated", 26);
|
||||
public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 27);
|
||||
public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 28);
|
||||
public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 29);
|
||||
public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 30);
|
||||
public static final DebugMessageType sessionId = new DebugMessageType("sessionId", 31);
|
||||
public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 32);
|
||||
public static final DebugMessageType outputRedirect = new DebugMessageType("outputRedirect", 333);
|
||||
public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 23);
|
||||
public static final DebugMessageType error = new DebugMessageType("error", 24);
|
||||
public static final DebugMessageType terminated = new DebugMessageType("terminated", 25);
|
||||
public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 26);
|
||||
public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 27);
|
||||
public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 28);
|
||||
public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 29);
|
||||
public static final DebugMessageType sessionId = new DebugMessageType("sessionId", 30);
|
||||
public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 31);
|
||||
public static final DebugMessageType outputRedirect = new DebugMessageType("outputRedirect", 32);
|
||||
|
||||
protected static DebugMessageType[] ENUMS = new DebugMessageType[] {
|
||||
start,
|
||||
@@ -89,7 +88,6 @@ public class DebugMessageType extends EnumType {
|
||||
suspendedOnStepping,
|
||||
suspendedOnError,
|
||||
resumedOnSteppingEnd,
|
||||
resumedOnError,
|
||||
error,
|
||||
terminated,
|
||||
clientRequestCallgraphReply,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
@@ -14,8 +16,13 @@ public class J2sePlatform extends Platform {
|
||||
return new InputStreamReader(inputStream);
|
||||
}
|
||||
|
||||
public InputStream openFile(String fileName) {
|
||||
return getClass().getResourceAsStream("/" + fileName);
|
||||
public InputStream openFile(String filePath) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(new File(filePath));
|
||||
return fis;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.InputStream;
|
||||
|
||||
import org.luaj.compiler.LuaC;
|
||||
import org.luaj.debug.DebugLuaState;
|
||||
import org.luaj.lib.PackageLib;
|
||||
import org.luaj.lib.j2se.LuajavaLib;
|
||||
import org.luaj.vm.LClosure;
|
||||
import org.luaj.vm.LPrototype;
|
||||
@@ -52,6 +53,7 @@ public class StandardLuaJVM {
|
||||
protected boolean bSuspendOnStart = false;
|
||||
protected String script;
|
||||
protected String[] scriptArgs;
|
||||
protected String luaPath;
|
||||
protected LuaState state;
|
||||
protected boolean isReady = false;
|
||||
protected boolean isTerminated = false;
|
||||
@@ -67,7 +69,7 @@ public class StandardLuaJVM {
|
||||
|
||||
protected void printUsage() {
|
||||
System.out.println("Usage:");
|
||||
System.out.println("\t java StandardLuaJVM [-Dport=<port>[,suspendedOnStart=<true|false>]] <script> [<script arguments>]");
|
||||
System.out.println("\t java StandardLuaJVM [-Dport=<port>[,suspendedOnStart=<true|false>]] [-L<lua path>] <script> [<script arguments>]");
|
||||
System.out.println("where [] denotes an optional argument and <> denotes a placeholder.");
|
||||
}
|
||||
|
||||
@@ -76,7 +78,8 @@ public class StandardLuaJVM {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
|
||||
if (args[0] != null && args[0].startsWith("-D")) {
|
||||
int index = 0;
|
||||
if (args[index] != null && args[index].startsWith("-D")) {
|
||||
if (args.length < 2) {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
@@ -84,7 +87,7 @@ public class StandardLuaJVM {
|
||||
this.isDebugMode = true;
|
||||
System.setProperty(LuaState.PROPERTY_LUAJ_DEBUG, "true");
|
||||
|
||||
String debugOptions = args[0];
|
||||
String debugOptions = args[index];
|
||||
debugOptions = debugOptions.substring(2); // remove '-D'
|
||||
String[] options = debugOptions.split(",");
|
||||
for (int i = 0; options != null && i < options.length; i++) {
|
||||
@@ -118,13 +121,24 @@ public class StandardLuaJVM {
|
||||
throw new ParseException("Invalid command line: debug port is missing");
|
||||
}
|
||||
|
||||
int tempArgsCount = args.length - 1;
|
||||
String[] tempArgs = new String[tempArgsCount];
|
||||
System.arraycopy(args, 1, tempArgs, 0, tempArgsCount);
|
||||
parseScriptArgs(tempArgs);
|
||||
} else {
|
||||
parseScriptArgs(args);
|
||||
index++;
|
||||
}
|
||||
|
||||
if (args[index] != null && args[index].startsWith("-L")) {
|
||||
luaPath = args[index].substring(2); //remove -L fromt the arg
|
||||
index++;
|
||||
}
|
||||
|
||||
String[] scriptArgStrs;
|
||||
if (index != 0) {
|
||||
int scriptArgsCount = args.length - index;
|
||||
scriptArgStrs = new String[scriptArgsCount];
|
||||
System.arraycopy(args, index, scriptArgStrs, 0, scriptArgsCount);
|
||||
} else {
|
||||
scriptArgStrs = args;
|
||||
}
|
||||
|
||||
parseScriptArgs(scriptArgStrs);
|
||||
}
|
||||
|
||||
private void parseScriptArgs(String[] args)
|
||||
@@ -169,6 +183,10 @@ public class StandardLuaJVM {
|
||||
return this.scriptArgs;
|
||||
}
|
||||
|
||||
String getLuaPath() {
|
||||
return this.luaPath;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
// new lua debug state
|
||||
@@ -215,6 +233,11 @@ public class StandardLuaJVM {
|
||||
|
||||
// add the compiler
|
||||
LuaC.install();
|
||||
|
||||
// set the lua path if present
|
||||
if (luaPath != null && luaPath.trim().length() > 0) {
|
||||
PackageLib.setLuaPath(luaPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ public class DebugResponseCallgraph extends DebugMessage {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuffer buffer = new StringBuffer("callgraph: ");
|
||||
for (int i = 0; i < stackFrames.length; i++) {
|
||||
StackFrame frame = stackFrames[i];
|
||||
buffer.append(frame.toString());
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DebugResponseVariables extends DebugMessage {
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuffer buffer = new StringBuffer(getType().toString() + ":");
|
||||
for (int i = 0; variables != null && i < variables.length; i++) {
|
||||
buffer.append("\t" + variables[i].getName() + ":" + variables[i].getIndex() + "\n");
|
||||
}
|
||||
|
||||
@@ -216,7 +216,28 @@ public class LuaJVMTest extends TestCase {
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
}
|
||||
|
||||
args = new String[] { "-LC:\\lua\\scripts", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals("C:\\lua\\scripts", vm.getLuaPath());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-Dport=1044", "-LC:\\lua\\scripts", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals("C:\\lua\\scripts", vm.getLuaPath());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
}
|
||||
|
||||
public void testRun() {
|
||||
|
||||
Reference in New Issue
Block a user