Mercurial Hosting > luan
view core/src/luan/impl/IndexExpr.java @ 438:153326a0ef85
Added tag 0.6 for changeset 6cfbf45a1885
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 04 May 2015 11:08:09 -0600 |
parents | 23a93c118042 |
children | b48cfa14ba60 |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanException; import luan.LuanTable; import luan.LuanFunction; import luan.LuanSource; import luan.LuanMeta; import luan.modules.StringLuan; import luan.modules.BinaryLuan; import luan.modules.JavaLuan; final class IndexExpr extends BinaryOpExpr { IndexExpr(LuanSource.Element se,Expr op1,Expr op2) { super(se,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { return index(luan,op1.eval(luan),op2.eval(luan)); } private Object index(LuanStateImpl luan,Object obj,Object key) throws LuanException { if( obj instanceof LuanTable ) { LuanTable tbl = (LuanTable)obj; return tbl.get(luan,key); } if( obj instanceof String ) return StringLuan.__index(luan,(String)obj,key); if( obj instanceof byte[] ) return BinaryLuan.__index(luan,(byte[])obj,key); if( obj != null && luan.currentEnvironment().hasJava() ) return JavaLuan.__index(luan,obj,key); else throw luan.bit(op1.se()).exception( "attempt to index '"+op1.se().text()+"' (a " + Luan.type(obj) + " value)" ); } }