Fix metamethods for compare with numbers.
```
t = {}
t.__lt = function (a,b,c)
collectgarbage()
assert(c == nil)
if type(a) == 'table' then a = a.x end
if type(b) == 'table' then b = b.x end
return a<b, "dummy"
end
function Op(x) return setmetatable({x=x}, t) end
local function test ()
assert(not(Op(1)<Op(1)) and (Op(1)<Op(2)) and not(Op(2)<Op(1)))
assert(not(1 < Op(1)) and (Op(1) < 2) and not(2 < Op(1)))
assert(not(Op('a')<Op('a')) and (Op('a')<Op('b')) and not(Op('b')<Op('a')))
assert(not('a' < Op('a')) and (Op('a') < 'b') and not(Op('b') < Op('a')))
assert((Op(1)<=Op(1)) and (Op(1)<=Op(2)) and not(Op(2)<=Op(1)))
assert((Op('a')<=Op('a')) and (Op('a')<=Op('b')) and not(Op('b')<=Op('a')))
assert(not(Op(1)>Op(1)) and not(Op(1)>Op(2)) and (Op(2)>Op(1)))
assert(not(Op('a')>Op('a')) and not(Op('a')>Op('b')) and (Op('b')>Op('a')))
assert((Op(1)>=Op(1)) and not(Op(1)>=Op(2)) and (Op(2)>=Op(1)))
assert((1 >= Op(1)) and not(1 >= Op(2)) and (Op(2) >= 1))
assert((Op('a')>=Op('a')) and not(Op('a')>=Op('b')) and (Op('b')>=Op('a')))
assert(('a' >= Op('a')) and not(Op('a') >= 'b') and (Op('b') >= Op('a')))
end
test()
```
This commit is contained in:
@@ -206,28 +206,28 @@ public class LuaDouble extends LuaNumber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// relational operators
|
// relational operators
|
||||||
public LuaValue lt( LuaValue rhs ) { return rhs.gt_b(v)? LuaValue.TRUE: FALSE; }
|
public LuaValue lt( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.gt_b(v)? TRUE: FALSE) : super.lt(rhs); }
|
||||||
public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
|
public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
|
||||||
public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
|
public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
|
||||||
public boolean lt_b( LuaValue rhs ) { return rhs.gt_b(v); }
|
public boolean lt_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.gt_b(v) : super.lt_b(rhs); }
|
||||||
public boolean lt_b( int rhs ) { return v < rhs; }
|
public boolean lt_b( int rhs ) { return v < rhs; }
|
||||||
public boolean lt_b( double rhs ) { return v < rhs; }
|
public boolean lt_b( double rhs ) { return v < rhs; }
|
||||||
public LuaValue lteq( LuaValue rhs ) { return rhs.gteq_b(v)? LuaValue.TRUE: FALSE; }
|
public LuaValue lteq( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.gteq_b(v)? TRUE: FALSE) : super.lteq(rhs); }
|
||||||
public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
|
public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
|
||||||
public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
|
public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
|
||||||
public boolean lteq_b( LuaValue rhs ) { return rhs.gteq_b(v); }
|
public boolean lteq_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.gteq_b(v) : super.lteq_b(rhs); }
|
||||||
public boolean lteq_b( int rhs ) { return v <= rhs; }
|
public boolean lteq_b( int rhs ) { return v <= rhs; }
|
||||||
public boolean lteq_b( double rhs ) { return v <= rhs; }
|
public boolean lteq_b( double rhs ) { return v <= rhs; }
|
||||||
public LuaValue gt( LuaValue rhs ) { return rhs.lt_b(v)? LuaValue.TRUE: FALSE; }
|
public LuaValue gt( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.lt_b(v)? TRUE: FALSE) : super.gt(rhs); }
|
||||||
public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
|
public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
|
||||||
public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
|
public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
|
||||||
public boolean gt_b( LuaValue rhs ) { return rhs.lt_b(v); }
|
public boolean gt_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.lt_b(v) : super.gt_b(rhs); }
|
||||||
public boolean gt_b( int rhs ) { return v > rhs; }
|
public boolean gt_b( int rhs ) { return v > rhs; }
|
||||||
public boolean gt_b( double rhs ) { return v > rhs; }
|
public boolean gt_b( double rhs ) { return v > rhs; }
|
||||||
public LuaValue gteq( LuaValue rhs ) { return rhs.lteq_b(v)? LuaValue.TRUE: FALSE; }
|
public LuaValue gteq( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.lteq_b(v)? TRUE: FALSE) : super.gteq(rhs); }
|
||||||
public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
|
public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
|
||||||
public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
|
public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
|
||||||
public boolean gteq_b( LuaValue rhs ) { return rhs.lteq_b(v); }
|
public boolean gteq_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.lteq_b(v) : super.gteq_b(rhs); }
|
||||||
public boolean gteq_b( int rhs ) { return v >= rhs; }
|
public boolean gteq_b( int rhs ) { return v >= rhs; }
|
||||||
public boolean gteq_b( double rhs ) { return v >= rhs; }
|
public boolean gteq_b( double rhs ) { return v >= rhs; }
|
||||||
|
|
||||||
|
|||||||
@@ -172,28 +172,28 @@ public class LuaInteger extends LuaNumber {
|
|||||||
public LuaValue modFrom( double lhs ) { return LuaDouble.dmod(lhs,v); }
|
public LuaValue modFrom( double lhs ) { return LuaDouble.dmod(lhs,v); }
|
||||||
|
|
||||||
// relational operators
|
// relational operators
|
||||||
public LuaValue lt( LuaValue rhs ) { return rhs.gt_b(v)? TRUE: FALSE; }
|
public LuaValue lt( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.gt_b(v)? TRUE: FALSE) : super.lt(rhs); }
|
||||||
public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
|
public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
|
||||||
public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
|
public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
|
||||||
public boolean lt_b( LuaValue rhs ) { return rhs.gt_b(v); }
|
public boolean lt_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.gt_b(v) : super.lt_b(rhs); }
|
||||||
public boolean lt_b( int rhs ) { return v < rhs; }
|
public boolean lt_b( int rhs ) { return v < rhs; }
|
||||||
public boolean lt_b( double rhs ) { return v < rhs; }
|
public boolean lt_b( double rhs ) { return v < rhs; }
|
||||||
public LuaValue lteq( LuaValue rhs ) { return rhs.gteq_b(v)? TRUE: FALSE; }
|
public LuaValue lteq( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.gteq_b(v)? TRUE: FALSE) : super.lteq(rhs); }
|
||||||
public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
|
public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
|
||||||
public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
|
public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
|
||||||
public boolean lteq_b( LuaValue rhs ) { return rhs.gteq_b(v); }
|
public boolean lteq_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.gteq_b(v) : super.lteq_b(rhs); }
|
||||||
public boolean lteq_b( int rhs ) { return v <= rhs; }
|
public boolean lteq_b( int rhs ) { return v <= rhs; }
|
||||||
public boolean lteq_b( double rhs ) { return v <= rhs; }
|
public boolean lteq_b( double rhs ) { return v <= rhs; }
|
||||||
public LuaValue gt( LuaValue rhs ) { return rhs.lt_b(v)? TRUE: FALSE; }
|
public LuaValue gt( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.lt_b(v)? TRUE: FALSE) : super.gt(rhs); }
|
||||||
public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
|
public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
|
||||||
public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
|
public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
|
||||||
public boolean gt_b( LuaValue rhs ) { return rhs.lt_b(v); }
|
public boolean gt_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.lt_b(v) : super.gt_b(rhs); }
|
||||||
public boolean gt_b( int rhs ) { return v > rhs; }
|
public boolean gt_b( int rhs ) { return v > rhs; }
|
||||||
public boolean gt_b( double rhs ) { return v > rhs; }
|
public boolean gt_b( double rhs ) { return v > rhs; }
|
||||||
public LuaValue gteq( LuaValue rhs ) { return rhs.lteq_b(v)? TRUE: FALSE; }
|
public LuaValue gteq( LuaValue rhs ) { return rhs instanceof LuaNumber ? (rhs.lteq_b(v)? TRUE: FALSE) : super.gteq(rhs); }
|
||||||
public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
|
public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
|
||||||
public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
|
public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
|
||||||
public boolean gteq_b( LuaValue rhs ) { return rhs.lteq_b(v); }
|
public boolean gteq_b( LuaValue rhs ) { return rhs instanceof LuaNumber ? rhs.lteq_b(v) : super.gteq_b(rhs); }
|
||||||
public boolean gteq_b( int rhs ) { return v >= rhs; }
|
public boolean gteq_b( int rhs ) { return v >= rhs; }
|
||||||
public boolean gteq_b( double rhs ) { return v >= rhs; }
|
public boolean gteq_b( double rhs ) { return v >= rhs; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user