comparison src/luan/interp/ConcatExpr.java @ 40:e3624b7cd603

implement stack trace git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 21 Dec 2012 10:45:54 +0000
parents 8a57ebfdfd78
children 64ecb7a3aad7
comparison
equal deleted inserted replaced
39:e5bcb1eeafc1 40:e3624b7cd603
1 package luan.interp; 1 package luan.interp;
2 2
3 import luan.Lua; 3 import luan.Lua;
4 import luan.LuaFunction; 4 import luan.LuaFunction;
5 import luan.LuaException; 5 import luan.LuaException;
6 import luan.LuaSource;
6 7
7 8
8 final class ConcatExpr extends BinaryOpExpr { 9 final class ConcatExpr extends BinaryOpExpr {
9 10
10 ConcatExpr(Expr op1,Expr op2) { 11 ConcatExpr(LuaSource.Element se,Expr op1,Expr op2) {
11 super(op1,op2); 12 super(se,op1,op2);
12 } 13 }
13 14
14 @Override public Object eval(LuaStateImpl lua) throws LuaException { 15 @Override public Object eval(LuaStateImpl lua) throws LuaException {
15 Object o1 = op1.eval(lua); 16 Object o1 = op1.eval(lua);
16 Object o2 = op2.eval(lua); 17 Object o2 = op2.eval(lua);
17 String s1 = Lua.asString(o1); 18 String s1 = Lua.asString(o1);
18 String s2 = Lua.asString(o2); 19 String s2 = Lua.asString(o2);
19 if( s1 != null && s2 != null ) 20 if( s1 != null && s2 != null )
20 return s1 + s2; 21 return s1 + s2;
21 LuaFunction fn = lua.getBinHandler("__concat",o1,o2); 22 LuaFunction fn = lua.getBinHandler(se,"__concat",o1,o2);
22 if( fn != null ) 23 if( fn != null )
23 return Utils.first(fn.call(lua,o1,o2)); 24 return Lua.first(lua.call(fn,se,"__concat",o1,o2));
24 String type = s1==null ? Lua.type(o1) : Lua.type(o2); 25 String type = s1==null ? Lua.type(o1) : Lua.type(o2);
25 throw new LuaException( "attempt to concatenate a " + type + " value" ); 26 throw new LuaException( lua, se, "attempt to concatenate a " + type + " value" );
26 } 27 }
27 } 28 }