Mercurial Hosting > luan
comparison src/luan/interp/LeExpr.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 8a57ebfdfd78 |
children | a443637829c1 |
comparison
equal
deleted
inserted
replaced
39:e5bcb1eeafc1 | 40:e3624b7cd603 |
---|---|
2 | 2 |
3 import luan.Lua; | 3 import luan.Lua; |
4 import luan.LuaNumber; | 4 import luan.LuaNumber; |
5 import luan.LuaFunction; | 5 import luan.LuaFunction; |
6 import luan.LuaException; | 6 import luan.LuaException; |
7 import luan.LuaSource; | |
7 | 8 |
8 | 9 |
9 final class LeExpr extends BinaryOpExpr { | 10 final class LeExpr extends BinaryOpExpr { |
10 | 11 |
11 LeExpr(Expr op1,Expr op2) { | 12 LeExpr(LuaSource.Element se,Expr op1,Expr op2) { |
12 super(op1,op2); | 13 super(se,op1,op2); |
13 } | 14 } |
14 | 15 |
15 @Override public Object eval(LuaStateImpl lua) throws LuaException { | 16 @Override public Object eval(LuaStateImpl lua) throws LuaException { |
16 Object o1 = op1.eval(lua); | 17 Object o1 = op1.eval(lua); |
17 Object o2 = op2.eval(lua); | 18 Object o2 = op2.eval(lua); |
23 if( o1 instanceof String && o2 instanceof String ) { | 24 if( o1 instanceof String && o2 instanceof String ) { |
24 String s1 = (String)o1; | 25 String s1 = (String)o1; |
25 String s2 = (String)o2; | 26 String s2 = (String)o2; |
26 return s1.compareTo(s2) <= 0; | 27 return s1.compareTo(s2) <= 0; |
27 } | 28 } |
28 LuaFunction fn = lua.getBinHandler("__le",o1,o2); | 29 LuaFunction fn = lua.getBinHandler(se,"__le",o1,o2); |
29 if( fn != null ) | 30 if( fn != null ) |
30 return Lua.toBoolean( Utils.first(fn.call(lua,o1,o2)) ); | 31 return Lua.toBoolean( Lua.first(lua.call(fn,se,"__le",o1,o2)) ); |
31 fn = lua.getBinHandler("__lt",o1,o2); | 32 fn = lua.getBinHandler(se,"__lt",o1,o2); |
32 if( fn != null ) | 33 if( fn != null ) |
33 return !Lua.toBoolean( Utils.first(fn.call(lua,o2,o1)) ); | 34 return !Lua.toBoolean( Lua.first(lua.call(fn,se,"__lt",o2,o1)) ); |
34 throw new LuaException( "attempt to compare " + Lua.type(o1) + " with " + Lua.type(o2) ); | 35 throw new LuaException( lua, se, "attempt to compare " + Lua.type(o1) + " with " + Lua.type(o2) ); |
35 } | 36 } |
36 } | 37 } |