Mercurial Hosting > luan
view src/luan/interp/FnCall.java @ 56:c84274b18f0c
various
git-svn-id: https://luan-java.googlecode.com/svn/trunk@57 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 04 Jan 2013 21:35:55 +0000 |
parents | 8ede219cd111 |
children | 6ca02b188dba |
line wrap: on
line source
package luan.interp; import luan.Luan; import luan.LuanFunction; import luan.LuanException; import luan.LuanSource; final class FnCall extends CodeImpl implements Expressions { final Expr fnExpr; final Expressions args; final String fnName; FnCall(LuanSource.Element se,Expr fnExpr,Expressions args) { super(se); this.fnExpr = fnExpr; this.args = args; this.fnName = fnExpr.se().text(); } @Override public Object[] eval(LuanStateImpl luan) throws LuanException { return call( luan, fnExpr.eval(luan) ); } private Object[] call(LuanStateImpl luan,Object o) throws LuanException { if( o instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)o; return luan.call( fn, se, fnName, args.eval(luan) ); } Object h = luan.getHandler("__call",o); if( h != null ) return call(luan,h); throw new LuanException( luan, fnExpr.se(), "attempt to call '"+fnExpr.se().text()+"' (a " + Luan.type(o) + " value)" ); } }