Mercurial Hosting > luan
view src/luan/interp/SetTableEntry.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 8a57ebfdfd78 |
children | 64ecb7a3aad7 |
line wrap: on
line source
package luan.interp; import luan.LuaException; import luan.LuaTable; import luan.Lua; import luan.LuaFunction; import luan.LuaSource; final class SetTableEntry extends CodeImpl implements Settable { private final Expr tableExpr; private final Expr keyExpr; SetTableEntry(LuaSource.Element se,Expr tableExpr,Expr keyExpr) { super(se); this.tableExpr = tableExpr; this.keyExpr = keyExpr; } @Override public void set(LuaStateImpl lua,Object value) throws LuaException { newindex( lua, tableExpr.eval(lua), keyExpr.eval(lua), value ); } private void newindex(LuaStateImpl lua,Object t,Object key,Object value) throws LuaException { Object h; if( t instanceof LuaTable ) { LuaTable table = (LuaTable)t; Object old = table.put(key,value); if( old != null ) return; h = lua.getHandler("__newindex",t); if( h==null ) return; table.put(key,old); } else { h = lua.getHandler("__newindex",t); if( h==null ) throw new LuaException( lua, se, "attempt to index a " + Lua.type(t) + " value" ); } if( h instanceof LuaFunction ) { LuaFunction fn = (LuaFunction)h; lua.call(fn,se,"__newindex",t,key,value); } newindex(lua,h,key,value); } }