comparison src/luan/interp/LeExpr.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.LuaException; 5 import luan.LuanException;
6 import luan.LuaSource; 6 import luan.LuanSource;
7 7
8 8
9 final class LeExpr extends BinaryOpExpr { 9 final class LeExpr extends BinaryOpExpr {
10 10
11 LeExpr(LuaSource.Element se,Expr op1,Expr op2) { 11 LeExpr(LuanSource.Element se,Expr op1,Expr op2) {
12 super(se,op1,op2); 12 super(se,op1,op2);
13 } 13 }
14 14
15 @Override public Object eval(LuaStateImpl lua) throws LuaException { 15 @Override public Object eval(LuanStateImpl lua) throws LuanException {
16 Object o1 = op1.eval(lua); 16 Object o1 = op1.eval(lua);
17 Object o2 = op2.eval(lua); 17 Object o2 = op2.eval(lua);
18 if( o1 instanceof Number && o2 instanceof Number ) { 18 if( o1 instanceof Number && o2 instanceof Number ) {
19 Number n1 = (Number)o1; 19 Number n1 = (Number)o1;
20 Number n2 = (Number)o2; 20 Number n2 = (Number)o2;
23 if( o1 instanceof String && o2 instanceof String ) { 23 if( o1 instanceof String && o2 instanceof String ) {
24 String s1 = (String)o1; 24 String s1 = (String)o1;
25 String s2 = (String)o2; 25 String s2 = (String)o2;
26 return s1.compareTo(s2) <= 0; 26 return s1.compareTo(s2) <= 0;
27 } 27 }
28 LuaFunction fn = lua.getBinHandler(se,"__le",o1,o2); 28 LuanFunction fn = lua.getBinHandler(se,"__le",o1,o2);
29 if( fn != null ) 29 if( fn != null )
30 return Lua.toBoolean( Lua.first(lua.call(fn,se,"__le",o1,o2)) ); 30 return Luan.toBoolean( Luan.first(lua.call(fn,se,"__le",o1,o2)) );
31 fn = lua.getBinHandler(se,"__lt",o1,o2); 31 fn = lua.getBinHandler(se,"__lt",o1,o2);
32 if( fn != null ) 32 if( fn != null )
33 return !Lua.toBoolean( Lua.first(lua.call(fn,se,"__lt",o2,o1)) ); 33 return !Luan.toBoolean( Luan.first(lua.call(fn,se,"__lt",o2,o1)) );
34 throw new LuaException( lua, se, "attempt to compare " + Lua.type(o1) + " with " + Lua.type(o2) ); 34 throw new LuanException( lua, se, "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
35 } 35 }
36 } 36 }