From a67783899f2bdb47db6fe415deec21111fa2e0e7 Mon Sep 17 00:00:00 2001 From: Shu Lei Date: Thu, 4 Oct 2007 21:04:38 +0000 Subject: [PATCH] removed Type.java and updated the depended files to use the new type constants --- src/main/java/lua/Lua.java | 1 - src/main/java/lua/debug/DebugStackState.java | 10 +-- src/main/java/lua/debug/TableVariable.java | 6 +- src/main/java/lua/debug/Variable.java | 10 +-- src/main/java/lua/value/Type.java | 87 -------------------- src/test/java/lua/debug/TypeTest.java | 39 --------- 6 files changed, 13 insertions(+), 140 deletions(-) delete mode 100644 src/main/java/lua/value/Type.java delete mode 100644 src/test/java/lua/debug/TypeTest.java diff --git a/src/main/java/lua/Lua.java b/src/main/java/lua/Lua.java index 19490457..6c541f86 100644 --- a/src/main/java/lua/Lua.java +++ b/src/main/java/lua/Lua.java @@ -1,6 +1,5 @@ package lua; -import lua.value.Type; /** * Constants for lua limits and opcodes diff --git a/src/main/java/lua/debug/DebugStackState.java b/src/main/java/lua/debug/DebugStackState.java index 4d9a7a5a..29c125d8 100644 --- a/src/main/java/lua/debug/DebugStackState.java +++ b/src/main/java/lua/debug/DebugStackState.java @@ -29,13 +29,13 @@ import java.util.Map; import java.util.Set; import lua.CallInfo; +import lua.Lua; import lua.StackState; import lua.addon.compile.LexState; import lua.io.LocVars; import lua.io.Proto; import lua.value.LTable; import lua.value.LValue; -import lua.value.Type; public class DebugStackState extends StackState implements DebugRequestListener { @@ -310,17 +310,17 @@ public class DebugStackState extends StackState implements DebugRequestListener variablesSeen.add(varName); LValue value = stack[callInfo.base + i]; if (value != null) { - Type type = Type.valueOf(value.luaGetTypeName().toJavaString()); + int type = value.luaGetType(); DebugUtils.print("\tType: " + type); - if (type == Type.table) { + if (type == Lua.LUA_TTABLE) { DebugUtils.println(" (selected)"); variables.add( new TableVariable(localVariableCount++, varName, type, (LTable) value)); - } else if (type != Type.function && - type != Type.thread) { + } else if (type != Lua.LUA_TFUNCTION && + type != LUA_TTHREAD) { DebugUtils.println(" (selected)"); variables.add( new Variable(localVariableCount++, diff --git a/src/main/java/lua/debug/TableVariable.java b/src/main/java/lua/debug/TableVariable.java index fa4cc116..e21ae3e9 100644 --- a/src/main/java/lua/debug/TableVariable.java +++ b/src/main/java/lua/debug/TableVariable.java @@ -21,9 +21,9 @@ ******************************************************************************/ package lua.debug; +import lua.Lua; import lua.value.LTable; import lua.value.LValue; -import lua.value.Type; public class TableVariable extends Variable { @@ -31,7 +31,7 @@ public class TableVariable extends Variable { protected String[] keys; 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); int size = table.size(); @@ -43,7 +43,7 @@ public class TableVariable extends Variable { this.keys[i] = keyValues[i].toString(); LValue value = table.get(keyValues[i]); if (value instanceof LTable) { - this.values[i] = new TableVariable(i, "", Type.table, (LTable)value); + this.values[i] = new TableVariable(i, "
", Lua.LUA_TTABLE, (LTable)value); } else { this.values[i] = value.toString(); } diff --git a/src/main/java/lua/debug/Variable.java b/src/main/java/lua/debug/Variable.java index e361f9cd..a4bedd29 100644 --- a/src/main/java/lua/debug/Variable.java +++ b/src/main/java/lua/debug/Variable.java @@ -23,7 +23,7 @@ package lua.debug; import java.io.Serializable; -import lua.value.Type; +import lua.Lua; public class Variable implements Serializable { private static final long serialVersionUID = 8194091816623233934L; @@ -31,9 +31,9 @@ public class Variable implements Serializable { protected int index; protected String name; 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.name = name; this.type = type; @@ -44,7 +44,7 @@ public class Variable implements Serializable { return this.name; } - public Type getType() { + public int getType() { return this.type; } @@ -61,6 +61,6 @@ public class Variable implements Serializable { */ @Override public String toString() { - return "index: " + getIndex() + " name:" + getName() + " type: " + getType() + " value:" + getValue(); + return "index: " + getIndex() + " name:" + getName() + " type: " + Lua.TYPE_NAMES[getType()] + " value:" + getValue(); } } diff --git a/src/main/java/lua/value/Type.java b/src/main/java/lua/value/Type.java deleted file mode 100644 index a6185520..00000000 --- a/src/main/java/lua/value/Type.java +++ /dev/null @@ -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