comparison src/luan/interp/FnCall.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 FnCall implements Expressions { 9 final class FnCall extends CodeImpl implements Expressions {
9 final Expr fnExpr; 10 final Expr fnExpr;
10 final Expressions args; 11 final Expressions args;
12 final String fnName;
11 13
12 FnCall(Expr fnExpr,Expressions args) { 14 FnCall(LuaSource.Element se,Expr fnExpr,Expressions args) {
15 super(se);
13 this.fnExpr = fnExpr; 16 this.fnExpr = fnExpr;
14 this.args = args; 17 this.args = args;
18 this.fnName = fnExpr.se().text();
15 } 19 }
16 20
17 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { 21 @Override public Object[] eval(LuaStateImpl lua) throws LuaException {
18 return call( lua, fnExpr.eval(lua) ); 22 return call( lua, fnExpr.eval(lua) );
19 } 23 }
20 24
21 private Object[] call(LuaStateImpl lua,Object o) throws LuaException { 25 private Object[] call(LuaStateImpl lua,Object o) throws LuaException {
22 if( o instanceof LuaFunction ) { 26 if( o instanceof LuaFunction ) {
23 LuaFunction fn = (LuaFunction)o; 27 LuaFunction fn = (LuaFunction)o;
24 return fn.call( lua, args.eval(lua) ); 28 return lua.call( fn, se, fnName, args.eval(lua) );
25 } 29 }
26 Object h = lua.getHandler("__call",o); 30 Object h = lua.getHandler("__call",o);
27 if( h != null ) 31 if( h != null )
28 return call(lua,h); 32 return call(lua,h);
29 throw new LuaException( "attempt to call a " + Lua.type(o) + " value" ); 33 throw new LuaException( lua, se, "attempt to call a " + Lua.type(o) + " value" );
30 } 34 }
31 } 35 }