Mercurial Hosting > luan
view core/src/luan/impl/FnCall.java @ 557:6268c1ce6ea8
sane queryparser update
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 21 Jun 2015 16:15:52 -0600 |
parents | b48cfa14ba60 |
children | 4723d22062ce |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanFunction; import luan.LuanException; import luan.LuanElement; import luan.LuanTable; final class FnCall extends CodeImpl implements Expressions { final Expr fnExpr; final Expressions args; final String fnName; FnCall(LuanElement el,Expr fnExpr,Expressions args) { super(el); this.fnExpr = fnExpr; this.args = args; this.fnName = fnExpr.el().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.bit(el).call( fn, fnName, Luan.array(args.eval(luan)) ); } if( o instanceof LuanTable ) { LuanTable t = (LuanTable)o; Object h = t.getHandler("__call"); if( h != null ) return call(luan,h); } throw luan.bit(fnExpr.el()).exception( "attempt to call '"+fnExpr.el().text()+"' (a " + Luan.type(o) + " value)" ); } @Override public String toString() { return "(FnCall "+fnName+" "+fnExpr+" "+args+")"; } }