comparison src/luan/interp/IndexExpr.java @ 49:8ede219cd111

add WebShell git-svn-id: https://luan-java.googlecode.com/svn/trunk@50 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 28 Dec 2012 19:35:04 +0000
parents 64ecb7a3aad7
children c84274b18f0c
comparison
equal deleted inserted replaced
48:64ecb7a3aad7 49:8ede219cd111
11 11
12 IndexExpr(LuanSource.Element se,Expr op1,Expr op2) { 12 IndexExpr(LuanSource.Element se,Expr op1,Expr op2) {
13 super(se,op1,op2); 13 super(se,op1,op2);
14 } 14 }
15 15
16 @Override public Object eval(LuanStateImpl lua) throws LuanException { 16 @Override public Object eval(LuanStateImpl luan) throws LuanException {
17 return index(lua,op1.eval(lua),op2.eval(lua)); 17 return index(luan,op1.eval(luan),op2.eval(luan));
18 } 18 }
19 19
20 private Object index(LuanStateImpl lua,Object t,Object key) throws LuanException { 20 private Object index(LuanStateImpl luan,Object t,Object key) throws LuanException {
21 Object h; 21 Object h;
22 if( t instanceof LuanTable ) { 22 if( t instanceof LuanTable ) {
23 LuanTable tbl = (LuanTable)t; 23 LuanTable tbl = (LuanTable)t;
24 Object value = tbl.get(key); 24 Object value = tbl.get(key);
25 if( value != null ) 25 if( value != null )
26 return value; 26 return value;
27 h = lua.getHandler("__index",t); 27 h = luan.getHandler("__index",t);
28 if( h==null ) 28 if( h==null )
29 return null; 29 return null;
30 } else { 30 } else {
31 h = lua.getHandler("__index",t); 31 h = luan.getHandler("__index",t);
32 if( h==null ) 32 if( h==null )
33 throw new LuanException( lua, se, "attempt to index a " + Luan.type(t) + " value" ); 33 throw new LuanException( luan, se, "attempt to index a " + Luan.type(t) + " value" );
34 } 34 }
35 if( h instanceof LuanFunction ) { 35 if( h instanceof LuanFunction ) {
36 LuanFunction fn = (LuanFunction)h; 36 LuanFunction fn = (LuanFunction)h;
37 return Luan.first(lua.call(fn,se,"__index",t,key)); 37 return Luan.first(luan.call(fn,se,"__index",t,key));
38 } 38 }
39 return index(lua,h,key); 39 return index(luan,h,key);
40 } 40 }
41 } 41 }