removed Type.java and updated the depended files to use the new type constants
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package lua;
|
package lua;
|
||||||
|
|
||||||
import lua.value.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for lua limits and opcodes
|
* Constants for lua limits and opcodes
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import lua.CallInfo;
|
import lua.CallInfo;
|
||||||
|
import lua.Lua;
|
||||||
import lua.StackState;
|
import lua.StackState;
|
||||||
import lua.addon.compile.LexState;
|
import lua.addon.compile.LexState;
|
||||||
import lua.io.LocVars;
|
import lua.io.LocVars;
|
||||||
import lua.io.Proto;
|
import lua.io.Proto;
|
||||||
import lua.value.LTable;
|
import lua.value.LTable;
|
||||||
import lua.value.LValue;
|
import lua.value.LValue;
|
||||||
import lua.value.Type;
|
|
||||||
|
|
||||||
public class DebugStackState extends StackState implements DebugRequestListener {
|
public class DebugStackState extends StackState implements DebugRequestListener {
|
||||||
|
|
||||||
@@ -310,17 +310,17 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
variablesSeen.add(varName);
|
variablesSeen.add(varName);
|
||||||
LValue value = stack[callInfo.base + i];
|
LValue value = stack[callInfo.base + i];
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
Type type = Type.valueOf(value.luaGetTypeName().toJavaString());
|
int type = value.luaGetType();
|
||||||
DebugUtils.print("\tType: " + type);
|
DebugUtils.print("\tType: " + type);
|
||||||
if (type == Type.table) {
|
if (type == Lua.LUA_TTABLE) {
|
||||||
DebugUtils.println(" (selected)");
|
DebugUtils.println(" (selected)");
|
||||||
variables.add(
|
variables.add(
|
||||||
new TableVariable(localVariableCount++,
|
new TableVariable(localVariableCount++,
|
||||||
varName,
|
varName,
|
||||||
type,
|
type,
|
||||||
(LTable) value));
|
(LTable) value));
|
||||||
} else if (type != Type.function &&
|
} else if (type != Lua.LUA_TFUNCTION &&
|
||||||
type != Type.thread) {
|
type != LUA_TTHREAD) {
|
||||||
DebugUtils.println(" (selected)");
|
DebugUtils.println(" (selected)");
|
||||||
variables.add(
|
variables.add(
|
||||||
new Variable(localVariableCount++,
|
new Variable(localVariableCount++,
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package lua.debug;
|
package lua.debug;
|
||||||
|
|
||||||
|
import lua.Lua;
|
||||||
import lua.value.LTable;
|
import lua.value.LTable;
|
||||||
import lua.value.LValue;
|
import lua.value.LValue;
|
||||||
import lua.value.Type;
|
|
||||||
|
|
||||||
public class TableVariable extends Variable {
|
public class TableVariable extends Variable {
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class TableVariable extends Variable {
|
|||||||
protected String[] keys;
|
protected String[] keys;
|
||||||
protected Object[] values;
|
protected Object[] values;
|
||||||
|
|
||||||
public TableVariable(int index, String name, Type type, LTable table) {
|
public TableVariable(int index, String name, int type, LTable table) {
|
||||||
super(index, name, type, null);
|
super(index, name, type, null);
|
||||||
|
|
||||||
int size = table.size();
|
int size = table.size();
|
||||||
@@ -43,7 +43,7 @@ public class TableVariable extends Variable {
|
|||||||
this.keys[i] = keyValues[i].toString();
|
this.keys[i] = keyValues[i].toString();
|
||||||
LValue value = table.get(keyValues[i]);
|
LValue value = table.get(keyValues[i]);
|
||||||
if (value instanceof LTable) {
|
if (value instanceof LTable) {
|
||||||
this.values[i] = new TableVariable(i, "<table>", Type.table, (LTable)value);
|
this.values[i] = new TableVariable(i, "<table>", Lua.LUA_TTABLE, (LTable)value);
|
||||||
} else {
|
} else {
|
||||||
this.values[i] = value.toString();
|
this.values[i] = value.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ package lua.debug;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lua.value.Type;
|
import lua.Lua;
|
||||||
|
|
||||||
public class Variable implements Serializable {
|
public class Variable implements Serializable {
|
||||||
private static final long serialVersionUID = 8194091816623233934L;
|
private static final long serialVersionUID = 8194091816623233934L;
|
||||||
@@ -31,9 +31,9 @@ public class Variable implements Serializable {
|
|||||||
protected int index;
|
protected int index;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String value;
|
protected String value;
|
||||||
protected Type type;
|
protected int type;
|
||||||
|
|
||||||
public Variable(int index, String name, Type type, String value) {
|
public Variable(int index, String name, int type, String value) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -44,7 +44,7 @@ public class Variable implements Serializable {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public int getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +61,6 @@ public class Variable implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "index: " + getIndex() + " name:" + getName() + " type: " + getType() + " value:" + getValue();
|
return "index: " + getIndex() + " name:" + getName() + " type: " + Lua.TYPE_NAMES[getType()] + " value:" + getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* 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
|
|
||||||
* THE SOFTWARE.
|
|
||||||
******************************************************************************/
|
|
||||||
package lua.value;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class Type implements Serializable, Comparable {
|
|
||||||
private static final long serialVersionUID = 877640303374122782L;
|
|
||||||
|
|
||||||
public static Type bool = new Type("boolean");
|
|
||||||
public static Type function = new Type("function");
|
|
||||||
public static Type nil = new Type("nil");
|
|
||||||
public static Type number = new Type("number");
|
|
||||||
public static Type string = new Type("string");
|
|
||||||
public static Type table = new Type("table");
|
|
||||||
public static Type thread = new Type("thread");
|
|
||||||
public static Type userdata = new Type("userdata");
|
|
||||||
protected static Type[] VALUES = new Type[] {
|
|
||||||
bool,
|
|
||||||
function,
|
|
||||||
nil,
|
|
||||||
number,
|
|
||||||
string,
|
|
||||||
table,
|
|
||||||
thread,
|
|
||||||
userdata
|
|
||||||
};
|
|
||||||
protected static int ORDINAL = 0;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private LString lname;
|
|
||||||
private int ordinal;
|
|
||||||
Type(String name) {
|
|
||||||
this.name = name;
|
|
||||||
this.lname = new LString(name);
|
|
||||||
this.ordinal = ORDINAL++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Enum#toString()
|
|
||||||
*/
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Type valueOf(String strValue) {
|
|
||||||
Type[] values = Type.VALUES;
|
|
||||||
for ( int i=0; i<values.length; i++ ) {
|
|
||||||
Type value = values[i];
|
|
||||||
if (value.toString().equals(strValue)) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("String '" + strValue + "' cannot be converted to enum Type");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
|
||||||
*/
|
|
||||||
public int compareTo(Object o) {
|
|
||||||
return this.ordinal - ((Type)o).ordinal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LString toLString() {
|
|
||||||
return lname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* 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
|
|
||||||
* THE SOFTWARE.
|
|
||||||
******************************************************************************/
|
|
||||||
package lua.debug;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import lua.value.Type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class TypeTest extends TestCase {
|
|
||||||
public void testEnumToString() {
|
|
||||||
assertEquals("boolean", Type.bool.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testStringToEnum() {
|
|
||||||
String boolStr = "boolean";
|
|
||||||
assertEquals(Type.bool, Type.valueOf(boolStr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user