comparison src/luan/interp/DivExpr.java @ 35:e51906de0f11

implement metatables git-svn-id: https://luan-java.googlecode.com/svn/trunk@36 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 18 Dec 2012 07:05:58 +0000
parents 5cf15507d77e
children 8a57ebfdfd78
comparison
equal deleted inserted replaced
34:0cdc1da466ee 35:e51906de0f11
10 DivExpr(Expr op1,Expr op2) { 10 DivExpr(Expr op1,Expr op2) {
11 super(op1,op2); 11 super(op1,op2);
12 } 12 }
13 13
14 @Override public Object eval(LuaStateImpl lua) throws LuaException { 14 @Override public Object eval(LuaStateImpl lua) throws LuaException {
15 double n1 = Lua.checkNumber(op1.eval(lua)).value(); 15 Object o1 = op1.eval(lua);
16 double n2 = Lua.checkNumber(op2.eval(lua)).value(); 16 Object o2 = op2.eval(lua);
17 return new LuaNumber( n1 / n2 ); 17 LuaNumber n1 = Lua.toNumber(o1);
18 LuaNumber n2 = Lua.toNumber(o2);
19 if( n1 != null && n2 != null )
20 return new LuaNumber( n1.value() / n2.value() );
21 return arithmetic(lua,"__div",o1,o2);
18 } 22 }
19 } 23 }