Mercurial Hosting > luan
comparison src/luan/interp/LtExpr.java @ 8:8896068e0a4b
finish operators
git-svn-id: https://luan-java.googlecode.com/svn/trunk@9 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 21 Nov 2012 06:57:09 +0000 |
parents | |
children | b7d7069fee58 |
comparison
equal
deleted
inserted
replaced
7:bca8fc5d928b | 8:8896068e0a4b |
---|---|
1 package luan.interp; | |
2 | |
3 import luan.Lua; | |
4 import luan.LuaNumber; | |
5 import luan.LuaException; | |
6 import luan.LuaState; | |
7 | |
8 | |
9 final class LtExpr extends BinaryOpExpr { | |
10 | |
11 LtExpr(Expr op1,Expr op2) { | |
12 super(op1,op2); | |
13 } | |
14 | |
15 @Override Object eval(LuaState lua) throws LuaException { | |
16 Object v1 = op1.eval(lua); | |
17 Object v2 = op2.eval(lua); | |
18 if( v1 instanceof LuaNumber && v2 instanceof LuaNumber ) { | |
19 LuaNumber n1 = (LuaNumber)v1; | |
20 LuaNumber n2 = (LuaNumber)v2; | |
21 return n1.compareTo(n2) < 0; | |
22 } | |
23 if( v1 instanceof String && v2 instanceof String ) { | |
24 String s1 = (String)v1; | |
25 String s2 = (String)v2; | |
26 return s1.compareTo(s2) < 0; | |
27 } | |
28 throw new LuaException( "attempt to compare " + Lua.type(v1) + " with " + Lua.type(v2) ); | |
29 } | |
30 } |