2007-06-08 05:11:37 +00:00
|
|
|
package lua.value;
|
|
|
|
|
|
2007-06-14 04:58:09 +00:00
|
|
|
import lua.Lua;
|
2007-06-08 05:11:37 +00:00
|
|
|
import lua.StackState;
|
|
|
|
|
|
|
|
|
|
public class LString extends LValue {
|
|
|
|
|
|
2007-07-16 02:37:08 +00:00
|
|
|
public static final LString TYPE_NAME = new LString("string");
|
|
|
|
|
|
2007-06-08 05:11:37 +00:00
|
|
|
final String m_string;
|
2007-06-24 15:04:19 +00:00
|
|
|
final int m_hash;
|
2007-06-08 05:11:37 +00:00
|
|
|
|
|
|
|
|
public LString(String string) {
|
|
|
|
|
this.m_string = string;
|
2007-06-24 15:04:19 +00:00
|
|
|
this.m_hash = string.hashCode();
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-10 22:53:09 +00:00
|
|
|
public boolean equals(Object o) {
|
2007-06-24 15:04:19 +00:00
|
|
|
if ( o != null && o instanceof LString ) {
|
|
|
|
|
LString s = (LString) o;
|
|
|
|
|
return m_hash == s.m_hash && m_string.equals(s.m_string);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2007-06-10 22:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int hashCode() {
|
2007-06-24 15:04:19 +00:00
|
|
|
return m_hash;
|
2007-06-10 22:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
2007-06-08 05:11:37 +00:00
|
|
|
// TODO: what to do with LuaState?
|
|
|
|
|
public LString(StackState l, String string) {
|
|
|
|
|
this(string);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-14 04:58:09 +00:00
|
|
|
public boolean luaBinCmpUnknown(int opcode, LValue lhs) {
|
|
|
|
|
return lhs.luaBinCmpString(opcode, m_string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean luaBinCmpString(int opcode, String rhs) {
|
|
|
|
|
switch ( opcode ) {
|
|
|
|
|
case Lua.OP_EQ: return m_string.equals(rhs);
|
|
|
|
|
case Lua.OP_LT: return m_string.compareTo(rhs) < 0;
|
|
|
|
|
case Lua.OP_LE: return m_string.compareTo(rhs) <= 0;
|
|
|
|
|
}
|
|
|
|
|
luaUnsupportedOperation();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 05:11:37 +00:00
|
|
|
public String luaAsString() {
|
|
|
|
|
return m_string;
|
|
|
|
|
}
|
2007-06-10 19:49:47 +00:00
|
|
|
|
|
|
|
|
/** Built-in opcode LEN, for Strings and Tables */
|
|
|
|
|
public LValue luaLength() {
|
|
|
|
|
return new LInteger( m_string.length() );
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-16 02:37:08 +00:00
|
|
|
public LString luaGetType() {
|
|
|
|
|
return TYPE_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 05:11:37 +00:00
|
|
|
}
|