Mercurial Hosting > luan
diff core/src/luan/impl/IndexExpr.java @ 502:d3183a330ff5
improve the __index metamethod to work with any type;
simplify luan_proxy to eliminate base;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 19 May 2015 17:57:20 -0600 |
parents | b48cfa14ba60 |
children | 2da0bcb979b5 |
line wrap: on
line diff
--- a/core/src/luan/impl/IndexExpr.java Mon May 18 23:23:01 2015 -0600 +++ b/core/src/luan/impl/IndexExpr.java Tue May 19 17:57:20 2015 -0600 @@ -1,14 +1,8 @@ package luan.impl; -import luan.Luan; import luan.LuanException; import luan.LuanTable; -import luan.LuanFunction; import luan.LuanElement; -import luan.LuanMeta; -import luan.modules.StringLuan; -import luan.modules.BinaryLuan; -import luan.modules.JavaLuan; final class IndexExpr extends BinaryOpExpr { @@ -18,21 +12,7 @@ } @Override public Object eval(LuanStateImpl luan) throws LuanException { - return index(luan,op1.eval(luan),op2.eval(luan)); + return LuanTable.index( luan.bit(op1.el()), 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.el()).exception( "attempt to index '"+op1.el().text()+"' (a " + Luan.type(obj) + " value)" ); - } }