comparison src/luan/interp/FnCall.java @ 35:e51906de0f11

implement metatables git-svn-id: https://luan-java.googlecode.com/svn/trunk@36 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 18 Dec 2012 07:05:58 +0000
parents 5cf15507d77e
children 2a35154aec14
comparison
equal deleted inserted replaced
34:0cdc1da466ee 35:e51906de0f11
13 this.fnExpr = fnExpr; 13 this.fnExpr = fnExpr;
14 this.args = args; 14 this.args = args;
15 } 15 }
16 16
17 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { 17 @Override public Object[] eval(LuaStateImpl lua) throws LuaException {
18 LuaFunction fn = Lua.checkFunction( fnExpr.eval(lua) ); 18 return call( lua, fnExpr.eval(lua) );
19 return fn.call( lua, args.eval(lua) ); 19 }
20
21 private Object[] call(LuaStateImpl lua,Object o) throws LuaException {
22 if( o instanceof LuaFunction ) {
23 LuaFunction fn = (LuaFunction)o;
24 return fn.call( lua, args.eval(lua) );
25 }
26 Object h = Utils.getHandlerObject("__call",o);
27 if( h != null )
28 return call(lua,h);
29 throw new LuaException( "attempt to call a " + Lua.type(o) + " value" );
20 } 30 }
21 } 31 }