comparison 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
comparison
equal deleted inserted replaced
39:e5bcb1eeafc1 40:e3624b7cd603
2 2
3 import luan.LuaException; 3 import luan.LuaException;
4 import luan.LuaTable; 4 import luan.LuaTable;
5 import luan.Lua; 5 import luan.Lua;
6 import luan.LuaFunction; 6 import luan.LuaFunction;
7 import luan.LuaSource;
7 8
8 9
9 final class SetTableEntry implements Settable { 10 final class SetTableEntry extends CodeImpl implements Settable {
10 private final Expr tableExpr; 11 private final Expr tableExpr;
11 private final Expr keyExpr; 12 private final Expr keyExpr;
12 13
13 SetTableEntry(Expr tableExpr,Expr keyExpr) { 14 SetTableEntry(LuaSource.Element se,Expr tableExpr,Expr keyExpr) {
15 super(se);
14 this.tableExpr = tableExpr; 16 this.tableExpr = tableExpr;
15 this.keyExpr = keyExpr; 17 this.keyExpr = keyExpr;
16 } 18 }
17 19
18 @Override public void set(LuaStateImpl lua,Object value) throws LuaException { 20 @Override public void set(LuaStateImpl lua,Object value) throws LuaException {
19 newindex( lua, tableExpr.eval(lua), keyExpr.eval(lua), value ); 21 newindex( lua, tableExpr.eval(lua), keyExpr.eval(lua), value );
20 } 22 }
21 23
22 private static void newindex(LuaStateImpl lua,Object t,Object key,Object value) throws LuaException { 24 private void newindex(LuaStateImpl lua,Object t,Object key,Object value) throws LuaException {
23 Object h; 25 Object h;
24 if( t instanceof LuaTable ) { 26 if( t instanceof LuaTable ) {
25 LuaTable table = (LuaTable)t; 27 LuaTable table = (LuaTable)t;
26 Object old = table.put(key,value); 28 Object old = table.put(key,value);
27 if( old != null ) 29 if( old != null )
31 return; 33 return;
32 table.put(key,old); 34 table.put(key,old);
33 } else { 35 } else {
34 h = lua.getHandler("__newindex",t); 36 h = lua.getHandler("__newindex",t);
35 if( h==null ) 37 if( h==null )
36 throw new LuaException( "attempt to index a " + Lua.type(t) + " value" ); 38 throw new LuaException( lua, se, "attempt to index a " + Lua.type(t) + " value" );
37 } 39 }
38 if( h instanceof LuaFunction ) { 40 if( h instanceof LuaFunction ) {
39 LuaFunction fn = (LuaFunction)h; 41 LuaFunction fn = (LuaFunction)h;
40 fn.call(lua,t,key,value); 42 lua.call(fn,se,"__newindex",t,key,value);
41 } 43 }
42 newindex(lua,h,key,value); 44 newindex(lua,h,key,value);
43 } 45 }
44 46
45 } 47 }