added getDebugHost() and getDebugPort() methods to Platform for convenience
This commit is contained in:
@@ -70,8 +70,12 @@ import org.luaj.lib.TableLib;
|
|||||||
*/
|
*/
|
||||||
public class LuaState extends Lua {
|
public class LuaState extends Lua {
|
||||||
|
|
||||||
public static final String PROPERTY_LUAJ_DEBUG = "Luaj-Debug";
|
protected static final String DEBUG_CLASS_NAME = "org.luaj.debug.DebugLuaState";
|
||||||
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;
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm;
|
package org.luaj.vm;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -27,83 +27,116 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton to manage platform-specific behaviors.
|
* Singleton to manage platform-specific behaviors.
|
||||||
*
|
*
|
||||||
* @deprecated - will probably be replaced with Config, LuaConfig or something similar.
|
* @deprecated - will probably be replaced with Config, LuaConfig or something
|
||||||
|
* similar.
|
||||||
*/
|
*/
|
||||||
abstract public class Platform {
|
abstract public class Platform {
|
||||||
private static Platform instance;
|
private static Platform instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton to be used for platform operations.
|
* Singleton to be used for platform operations.
|
||||||
*
|
*
|
||||||
* The default Platform gets files as resources,
|
* The default Platform gets files as resources, and converts them to
|
||||||
* and converts them to characters using the default
|
* characters using the default InputStreamReader class.
|
||||||
* InputStreamReader class.
|
*/
|
||||||
*/
|
public static Platform getInstance() {
|
||||||
public static Platform getInstance() {
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new Platform() {
|
instance = new Platform() {
|
||||||
public Reader createReader(InputStream inputStream) {
|
public Reader createReader(InputStream inputStream) {
|
||||||
return new InputStreamReader(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public InputStream openFile(String fileName) {
|
||||||
* Set the Platform instance.
|
return getClass().getResourceAsStream("/" + fileName);
|
||||||
*
|
}
|
||||||
* This may be useful to define a file search path,
|
|
||||||
* or custom character encoding conversion properties.
|
/**
|
||||||
*/
|
* Assumes J2SE platform, return the corresponding system
|
||||||
public static void setInstance( Platform platform ) {
|
* property
|
||||||
instance = platform;
|
*/
|
||||||
}
|
public String getProperty(String propertyName) {
|
||||||
|
return System.getProperty(propertyName);
|
||||||
/**
|
}
|
||||||
* Return an InputStream or null if not found for a particular file name.
|
|
||||||
* @param fileName Name of the file to open
|
/**
|
||||||
* @return InputStream or null if not found.
|
* Provides a J2SE DebugSupport instance.
|
||||||
*/
|
*/
|
||||||
abstract public InputStream openFile( String fileName );
|
public DebugNetSupport getDebugSupport() throws IOException {
|
||||||
|
return null;
|
||||||
/**
|
}
|
||||||
* Create Reader from an InputStream
|
};
|
||||||
* @param inputStream InputStream to read from
|
}
|
||||||
* @return Reader instance to use for character input
|
return instance;
|
||||||
*/
|
}
|
||||||
abstract public Reader createReader( InputStream inputStream );
|
|
||||||
|
/**
|
||||||
/**
|
* Set the Platform instance.
|
||||||
* Returns the value for the given platform property.
|
*
|
||||||
* @param propertyName Property name
|
* This may be useful to define a file search path, or custom character
|
||||||
* @return Property value
|
* encoding conversion properties.
|
||||||
*/
|
*/
|
||||||
abstract public String getProperty(String propertyName);
|
public static void setInstance(Platform platform) {
|
||||||
|
instance = platform;
|
||||||
/**
|
}
|
||||||
* Returns an platform dependent DebugSupport instance.
|
|
||||||
* @return an platform dependent DebugSupport instance.
|
/**
|
||||||
*/
|
* Return an InputStream or null if not found for a particular file name.
|
||||||
abstract public DebugNetSupport getDebugSupport() throws IOException;
|
*
|
||||||
|
* @param fileName
|
||||||
|
* Name of the file to open
|
||||||
|
* @return InputStream or null if not found.
|
||||||
|
*/
|
||||||
|
abstract public InputStream openFile(String fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Reader from an InputStream
|
||||||
|
*
|
||||||
|
* @param inputStream
|
||||||
|
* InputStream to read from
|
||||||
|
* @return Reader instance to use for character input
|
||||||
|
*/
|
||||||
|
abstract public Reader createReader(InputStream inputStream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value for the given platform property.
|
||||||
|
*
|
||||||
|
* @param propertyName
|
||||||
|
* Property name
|
||||||
|
* @return Property value
|
||||||
|
*/
|
||||||
|
abstract public String getProperty(String propertyName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an platform dependent DebugSupport instance.
|
||||||
|
*
|
||||||
|
* @return an platform dependent DebugSupport instance.
|
||||||
|
*/
|
||||||
|
abstract public DebugNetSupport getDebugSupport() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for the subclasses to figure out the debug host.
|
||||||
|
* @return the debug host property. If it is not present, null is returned.
|
||||||
|
*/
|
||||||
|
protected String getDebugHost() {
|
||||||
|
String host = getProperty(LuaState.PROPERTY_LUAJ_DEBUG_HOST);
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for the subclasses to figure out the debug port.
|
||||||
|
* @return -1 if the port is not found in the platform properties; the port
|
||||||
|
* as an integer if it is present in the platform properties and valid.
|
||||||
|
*/
|
||||||
|
protected int getDebugPort() {
|
||||||
|
String portStr = getProperty(LuaState.PROPERTY_LUAJ_DEBUG_PORT);
|
||||||
|
int port = -1;
|
||||||
|
if (portStr != null) {
|
||||||
|
try {
|
||||||
|
port = Integer.parseInt(portStr);
|
||||||
|
} catch (NumberFormatException e) {}
|
||||||
|
}
|
||||||
|
return port;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,7 @@ import org.luaj.vm.LuaState;
|
|||||||
import org.luaj.vm.Platform;
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
|
||||||
public class DebugLuaState extends LuaState implements DebugRequestListener {
|
public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||||
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 final boolean TRACE = (null != System.getProperty("TRACE"));
|
private static final boolean TRACE = (null != System.getProperty("TRACE"));
|
||||||
|
|
||||||
// stepping constants and stepping state
|
// stepping constants and stepping state
|
||||||
|
|||||||
@@ -66,26 +66,10 @@ public class LuaJVMTest extends TestCase {
|
|||||||
* Provides a J2SE DebugSupport instance.
|
* Provides a J2SE DebugSupport instance.
|
||||||
*/
|
*/
|
||||||
public DebugNetSupport getDebugSupport() throws IOException {
|
public DebugNetSupport getDebugSupport() throws IOException {
|
||||||
int port = getDebugPortNumber();
|
int port = getDebugPort();
|
||||||
DebugSupportImpl debugSupport = new DebugSupportImpl(port);
|
DebugSupportImpl debugSupport = new DebugSupportImpl(port);
|
||||||
return debugSupport;
|
return debugSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDebugPortNumber() throws IOException {
|
|
||||||
String portStr =
|
|
||||||
getProperty(DebugLuaState.PROPERTY_LUAJ_DEBUG_PORT);
|
|
||||||
int port = -1;
|
|
||||||
if (portStr == null) {
|
|
||||||
throw new IOException("Port number must be specified in the System property");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
port = Integer.parseInt(portStr);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new IOException("Bad port number: " + portStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user