Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/interp/LtExpr.java Wed Nov 21 06:57:09 2012 +0000 @@ -0,0 +1,30 @@ +package luan.interp; + +import luan.Lua; +import luan.LuaNumber; +import luan.LuaException; +import luan.LuaState; + + +final class LtExpr extends BinaryOpExpr { + + LtExpr(Expr op1,Expr op2) { + super(op1,op2); + } + + @Override Object eval(LuaState lua) throws LuaException { + Object v1 = op1.eval(lua); + Object v2 = op2.eval(lua); + if( v1 instanceof LuaNumber && v2 instanceof LuaNumber ) { + LuaNumber n1 = (LuaNumber)v1; + LuaNumber n2 = (LuaNumber)v2; + return n1.compareTo(n2) < 0; + } + if( v1 instanceof String && v2 instanceof String ) { + String s1 = (String)v1; + String s2 = (String)v2; + return s1.compareTo(s2) < 0; + } + throw new LuaException( "attempt to compare " + Lua.type(v1) + " with " + Lua.type(v2) ); + } +}