Mercurial Hosting > luan
comparison core/src/luan/impl/FnCall.java @ 171:3dcb0f9bee82
add core component
git-svn-id: https://luan-java.googlecode.com/svn/trunk@172 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 22 Jun 2014 05:41:22 +0000 |
parents | src/luan/impl/FnCall.java@4eaee12f6c65 |
children | d55e873e1f0d |
comparison
equal
deleted
inserted
replaced
170:7c792a328a83 | 171:3dcb0f9bee82 |
---|---|
1 package luan.impl; | |
2 | |
3 import luan.Luan; | |
4 import luan.LuanFunction; | |
5 import luan.LuanException; | |
6 import luan.LuanSource; | |
7 | |
8 | |
9 final class FnCall extends CodeImpl implements Expressions { | |
10 final Expr fnExpr; | |
11 final Expressions args; | |
12 final String fnName; | |
13 | |
14 FnCall(LuanSource.Element se,Expr fnExpr,Expressions args) { | |
15 super(se); | |
16 this.fnExpr = fnExpr; | |
17 this.args = args; | |
18 this.fnName = fnExpr.se().text(); | |
19 } | |
20 | |
21 @Override public Object eval(LuanStateImpl luan) throws LuanException { | |
22 return call( luan, fnExpr.eval(luan) ); | |
23 } | |
24 | |
25 private Object call(LuanStateImpl luan,Object o) throws LuanException { | |
26 if( o instanceof LuanFunction ) { | |
27 LuanFunction fn = (LuanFunction)o; | |
28 return luan.bit(se).call( fn, fnName, Luan.array(args.eval(luan)) ); | |
29 } | |
30 Object h = luan.getHandler("__call",o); | |
31 if( h != null ) | |
32 return call(luan,h); | |
33 throw luan.bit(fnExpr.se()).exception( "attempt to call '"+fnExpr.se().text()+"' (a " + Luan.type(o) + " value)" ); | |
34 } | |
35 | |
36 @Override public String toString() { | |
37 return "(FnCall "+fnName+" "+fnExpr+" "+args+")"; | |
38 } | |
39 } |