diff src/luan/interp/AddExpr.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
line wrap: on
line diff
--- a/src/luan/interp/AddExpr.java	Sun Dec 16 09:23:56 2012 +0000
+++ b/src/luan/interp/AddExpr.java	Tue Dec 18 07:05:58 2012 +0000
@@ -12,8 +12,12 @@
 	}
 
 	@Override public Object eval(LuaStateImpl lua) throws LuaException {
-		double n1 = Lua.checkNumber(op1.eval(lua)).value();
-		double n2 = Lua.checkNumber(op2.eval(lua)).value();
-		return new LuaNumber( n1 + n2 );
+		Object o1 = op1.eval(lua);
+		Object o2 = op2.eval(lua);
+		LuaNumber n1 = Lua.toNumber(o1);
+		LuaNumber n2 = Lua.toNumber(o2);
+		if( n1 != null && n2 != null )
+			return new LuaNumber( n1.value() + n2.value() );
+		return arithmetic(lua,"__add",o1,o2);
 	}
 }