Enhance binary compare operators, especially equals, to more closely match what standard lua does.

This commit is contained in:
James Roseborough
2007-06-14 04:58:09 +00:00
parent 14108aee87
commit 19bd995ba6
6 changed files with 93 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
package lua.value;
import lua.Lua;
import lua.StackState;
public class LString extends LValue {
@@ -23,6 +24,20 @@ public class LString extends LValue {
this(string);
}
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;
}
public String luaAsString() {
return m_string;
}