view core/src/luan/impl/ConcatExpr.java @ 509:e3b0846dc2ef

throw exception for invalid indexes of string, binary, or java
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 22 May 2015 02:02:49 -0600
parents b48cfa14ba60
children f1601a4ce1aa
line wrap: on
line source

package luan.impl;

import luan.Luan;
import luan.LuanFunction;
import luan.LuanException;
import luan.LuanElement;
import luan.LuanBit;


final class ConcatExpr extends BinaryOpExpr {

	ConcatExpr(LuanElement el,Expr op1,Expr op2) {
		super(el,op1,op2);
	}

	@Override public Object eval(LuanStateImpl luan) throws LuanException {
		Object o1 = op1.eval(luan);
		Object o2 = op2.eval(luan);
		LuanBit bit = luan.bit(el);
		LuanFunction fn = bit.getBinHandler("__concat",o1,o2);
		if( fn != null )
			return Luan.first(bit.call(fn,"__concat",new Object[]{o1,o2}));
		String s1 = luan.toString(o1);
		String s2 = luan.toString(o2);
		return s1 + s2;
	}
}