Mercurial Hosting > luan
view core/src/luan/impl/SetTableEntry.java @ 564:c8d4d69c6dd4
add examples/upload-and-email.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 04 Jul 2015 20:57:24 -0600 |
parents | e3fb9768dbb3 |
children | f1601a4ce1aa |
line wrap: on
line source
package luan.impl; import luan.LuanException; import luan.LuanTable; import luan.Luan; import luan.LuanFunction; import luan.LuanElement; import luan.LuanMeta; import luan.LuanBit; import luan.modules.JavaLuan; final class SetTableEntry extends CodeImpl implements Settable { private final Expr tableExpr; private final Expr keyExpr; SetTableEntry(LuanElement el,Expr tableExpr,Expr keyExpr) { super(el); 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 tbl = (LuanTable)t; tbl.put(luan,key,value); return; } LuanBit bit = luan.bit(el()); if( t != null && luan.hasJava() ) JavaLuan.__new_index(bit,t,key,value); else throw bit.exception( "attempt to index a " + Luan.type(t) + " value in '"+bit.el.text()+"'" ); } }