Mercurial Hosting > luan
comparison src/luan/interp/EqExpr.java @ 48:64ecb7a3aad7
rename Lua to Luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 03:29:12 +0000 |
parents | a443637829c1 |
children | 8ede219cd111 |
comparison
equal
deleted
inserted
replaced
47:659c7139e903 | 48:64ecb7a3aad7 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Lua; | 3 import luan.Luan; |
4 import luan.LuaFunction; | 4 import luan.LuanFunction; |
5 import luan.LuaTable; | 5 import luan.LuanTable; |
6 import luan.LuaException; | 6 import luan.LuanException; |
7 import luan.LuaSource; | 7 import luan.LuanSource; |
8 | 8 |
9 | 9 |
10 final class EqExpr extends BinaryOpExpr { | 10 final class EqExpr extends BinaryOpExpr { |
11 | 11 |
12 EqExpr(LuaSource.Element se,Expr op1,Expr op2) { | 12 EqExpr(LuanSource.Element se,Expr op1,Expr op2) { |
13 super(se,op1,op2); | 13 super(se,op1,op2); |
14 } | 14 } |
15 | 15 |
16 @Override public Object eval(LuaStateImpl lua) throws LuaException { | 16 @Override public Object eval(LuanStateImpl lua) throws LuanException { |
17 Object o1 = op1.eval(lua); | 17 Object o1 = op1.eval(lua); |
18 Object o2 = op2.eval(lua); | 18 Object o2 = op2.eval(lua); |
19 if( o1 == o2 || o1 != null && o1.equals(o2) ) | 19 if( o1 == o2 || o1 != null && o1.equals(o2) ) |
20 return true; | 20 return true; |
21 if( o1 instanceof Number && o2 instanceof Number ) { | 21 if( o1 instanceof Number && o2 instanceof Number ) { |
23 Number n2 = (Number)o2; | 23 Number n2 = (Number)o2; |
24 return n1.doubleValue() == n2.doubleValue(); | 24 return n1.doubleValue() == n2.doubleValue(); |
25 } | 25 } |
26 if( !o1.getClass().equals(o2.getClass()) ) | 26 if( !o1.getClass().equals(o2.getClass()) ) |
27 return false; | 27 return false; |
28 LuaTable mt1 = lua.getMetatable(o1); | 28 LuanTable mt1 = lua.getMetatable(o1); |
29 LuaTable mt2 = lua.getMetatable(o2); | 29 LuanTable mt2 = lua.getMetatable(o2); |
30 if( mt1==null || mt2==null ) | 30 if( mt1==null || mt2==null ) |
31 return false; | 31 return false; |
32 Object f = mt1.get("__eq"); | 32 Object f = mt1.get("__eq"); |
33 if( f == null || !f.equals(mt2.get("__eq")) ) | 33 if( f == null || !f.equals(mt2.get("__eq")) ) |
34 return null; | 34 return null; |
35 LuaFunction fn = lua.checkFunction(se,f); | 35 LuanFunction fn = lua.checkFunction(se,f); |
36 return Lua.toBoolean( Lua.first(lua.call(fn,se,"__eq",o1,o2)) ); | 36 return Luan.toBoolean( Luan.first(lua.call(fn,se,"__eq",o1,o2)) ); |
37 } | 37 } |
38 } | 38 } |