comparison core/src/luan/impl/IndexExpr.java @ 426:23a93c118042

fix LuanTable.get() to use metatables
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 18:44:20 -0600
parents b31d614343e8
children b48cfa14ba60
comparison
equal deleted inserted replaced
425:0a2fb80907f9 426:23a93c118042
22 } 22 }
23 23
24 private Object index(LuanStateImpl luan,Object obj,Object key) throws LuanException { 24 private Object index(LuanStateImpl luan,Object obj,Object key) throws LuanException {
25 if( obj instanceof LuanTable ) { 25 if( obj instanceof LuanTable ) {
26 LuanTable tbl = (LuanTable)obj; 26 LuanTable tbl = (LuanTable)obj;
27 Object value = tbl.get(key); 27 return tbl.get(luan,key);
28 if( value != null )
29 return value;
30 Object h = tbl.getHandler("__index");
31 if( h==null )
32 return null;
33 if( h instanceof LuanFunction ) {
34 LuanFunction fn = (LuanFunction)h;
35 return Luan.first(luan.bit(se).call(fn,"__index",new Object[]{tbl,key}));
36 }
37 if( h instanceof LuanMeta ) {
38 LuanMeta meta = (LuanMeta)h;
39 return meta.__index(luan,tbl,key);
40 }
41 return index(luan,h,key);
42 } 28 }
43 if( obj instanceof String ) 29 if( obj instanceof String )
44 return StringLuan.__index(luan,(String)obj,key); 30 return StringLuan.__index(luan,(String)obj,key);
45 if( obj instanceof byte[] ) 31 if( obj instanceof byte[] )
46 return BinaryLuan.__index(luan,(byte[])obj,key); 32 return BinaryLuan.__index(luan,(byte[])obj,key);