comparison core/src/luan/impl/ConcatExpr.java @ 410:0d6098a29b3e

fix ConcatExpr to use metamethod
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 29 Apr 2015 15:38:15 -0600
parents 3dcb0f9bee82
children b48cfa14ba60
comparison
equal deleted inserted replaced
409:abce9b0041b0 410:0d6098a29b3e
2 2
3 import luan.Luan; 3 import luan.Luan;
4 import luan.LuanFunction; 4 import luan.LuanFunction;
5 import luan.LuanException; 5 import luan.LuanException;
6 import luan.LuanSource; 6 import luan.LuanSource;
7 import luan.LuanBit;
7 8
8 9
9 final class ConcatExpr extends BinaryOpExpr { 10 final class ConcatExpr extends BinaryOpExpr {
10 11
11 ConcatExpr(LuanSource.Element se,Expr op1,Expr op2) { 12 ConcatExpr(LuanSource.Element se,Expr op1,Expr op2) {
13 } 14 }
14 15
15 @Override public Object eval(LuanStateImpl luan) throws LuanException { 16 @Override public Object eval(LuanStateImpl luan) throws LuanException {
16 Object o1 = op1.eval(luan); 17 Object o1 = op1.eval(luan);
17 Object o2 = op2.eval(luan); 18 Object o2 = op2.eval(luan);
19 LuanBit bit = luan.bit(se);
20 LuanFunction fn = bit.getBinHandler("__concat",o1,o2);
21 if( fn != null )
22 return Luan.first(bit.call(fn,"__concat",new Object[]{o1,o2}));
18 String s1 = luan.bit(op1.se()).toString(o1); 23 String s1 = luan.bit(op1.se()).toString(o1);
19 String s2 = luan.bit(op2.se()).toString(o2); 24 String s2 = luan.bit(op2.se()).toString(o2);
20 /*
21 if( s1 != null && s2 != null )
22 return s1 + s2;
23 LuanFunction fn = luan.getBinHandler(se,"__concat",o1,o2);
24 if( fn != null )
25 return Luan.first(luan.call(fn,se,"__concat",o1,o2));
26 String type = s1==null ? Luan.type(o1) : Luan.type(o2);
27 throw new LuanException( luan, se, "attempt to concatenate a " + type + " value" );
28 */
29 return s1 + s2; 25 return s1 + s2;
30 } 26 }
31 } 27 }