Mercurial Hosting > luan
view core/src/luan/impl/SetTableEntry.java @ 421:b31d614343e8
add Io.LuanString.text_writer();
improve java related errors;
fix to_string;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 15:13:14 -0600 |
parents | 8fbb961aabd5 |
children | 23a93c118042 |
line wrap: on
line source
package luan.impl; import luan.LuanException; import luan.LuanTable; import luan.Luan; import luan.LuanFunction; import luan.LuanSource; import luan.LuanMeta; import luan.modules.JavaLuan; final class SetTableEntry extends CodeImpl implements Settable { private final Expr tableExpr; private final Expr keyExpr; SetTableEntry(LuanSource.Element se,Expr tableExpr,Expr keyExpr) { super(se); this.tableExpr = tableExpr; this.keyExpr = keyExpr; } @Override public void set(LuanStateImpl luan,Object value) throws LuanException { newindex( luan, tableExpr.eval(luan), keyExpr.eval(luan), value ); } private void newindex(LuanStateImpl luan,Object t,Object key,Object value) throws LuanException { if( t instanceof LuanTable ) { LuanTable table = (LuanTable)t; Object h = table.getHandler("__newindex"); if( h==null || table.get(key)!=null ) { try { table.put(key,value); } catch(IllegalArgumentException e) { throw luan.bit(se).exception(e); } catch(UnsupportedOperationException e) { throw luan.bit(se).exception(e); } return; } if( h instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)h; luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value}); return; } if( h instanceof LuanMeta ) { LuanMeta meta = (LuanMeta)h; meta.__newindex(luan,table,key,value); return; } newindex(luan,h,key,value); } if( t != null && luan.currentEnvironment().hasJava() ) JavaLuan.__newindex(luan,t,key,value); else throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); } }