Mercurial Hosting > luan
view core/src/luan/impl/SetTableEntry.java @ 369:85bf9f0379aa
template statements no longer depend on 'Io' being defined
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 17 Apr 2015 06:25:38 -0600 |
parents | 05eb2837ddbf |
children | d55e873e1f0d |
line wrap: on
line source
package luan.impl; import luan.LuanException; import luan.LuanTable; import luan.Luan; import luan.LuanFunction; import luan.LuanSource; 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 { Object h; if( t instanceof LuanTable ) { LuanTable table = (LuanTable)t; h = luan.getHandler("__newindex",table); 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; } } else { h = luan.getHandler("__newindex",t); if( h==null ) throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); } if( h instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)h; luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value}); return; } newindex(luan,h,key,value); } }