Mercurial Hosting > luan
comparison src/luan/interp/SetTableEntry.java @ 48:64ecb7a3aad7
rename Lua to Luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 03:29:12 +0000 |
parents | e3624b7cd603 |
children | 8ede219cd111 |
comparison
equal
deleted
inserted
replaced
47:659c7139e903 | 48:64ecb7a3aad7 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.LuaException; | 3 import luan.LuanException; |
4 import luan.LuaTable; | 4 import luan.LuanTable; |
5 import luan.Lua; | 5 import luan.Luan; |
6 import luan.LuaFunction; | 6 import luan.LuanFunction; |
7 import luan.LuaSource; | 7 import luan.LuanSource; |
8 | 8 |
9 | 9 |
10 final class SetTableEntry extends CodeImpl implements Settable { | 10 final class SetTableEntry extends CodeImpl implements Settable { |
11 private final Expr tableExpr; | 11 private final Expr tableExpr; |
12 private final Expr keyExpr; | 12 private final Expr keyExpr; |
13 | 13 |
14 SetTableEntry(LuaSource.Element se,Expr tableExpr,Expr keyExpr) { | 14 SetTableEntry(LuanSource.Element se,Expr tableExpr,Expr keyExpr) { |
15 super(se); | 15 super(se); |
16 this.tableExpr = tableExpr; | 16 this.tableExpr = tableExpr; |
17 this.keyExpr = keyExpr; | 17 this.keyExpr = keyExpr; |
18 } | 18 } |
19 | 19 |
20 @Override public void set(LuaStateImpl lua,Object value) throws LuaException { | 20 @Override public void set(LuanStateImpl lua,Object value) throws LuanException { |
21 newindex( lua, tableExpr.eval(lua), keyExpr.eval(lua), value ); | 21 newindex( lua, tableExpr.eval(lua), keyExpr.eval(lua), value ); |
22 } | 22 } |
23 | 23 |
24 private void newindex(LuaStateImpl lua,Object t,Object key,Object value) throws LuaException { | 24 private void newindex(LuanStateImpl lua,Object t,Object key,Object value) throws LuanException { |
25 Object h; | 25 Object h; |
26 if( t instanceof LuaTable ) { | 26 if( t instanceof LuanTable ) { |
27 LuaTable table = (LuaTable)t; | 27 LuanTable table = (LuanTable)t; |
28 Object old = table.put(key,value); | 28 Object old = table.put(key,value); |
29 if( old != null ) | 29 if( old != null ) |
30 return; | 30 return; |
31 h = lua.getHandler("__newindex",t); | 31 h = lua.getHandler("__newindex",t); |
32 if( h==null ) | 32 if( h==null ) |
33 return; | 33 return; |
34 table.put(key,old); | 34 table.put(key,old); |
35 } else { | 35 } else { |
36 h = lua.getHandler("__newindex",t); | 36 h = lua.getHandler("__newindex",t); |
37 if( h==null ) | 37 if( h==null ) |
38 throw new LuaException( lua, se, "attempt to index a " + Lua.type(t) + " value" ); | 38 throw new LuanException( lua, se, "attempt to index a " + Luan.type(t) + " value" ); |
39 } | 39 } |
40 if( h instanceof LuaFunction ) { | 40 if( h instanceof LuanFunction ) { |
41 LuaFunction fn = (LuaFunction)h; | 41 LuanFunction fn = (LuanFunction)h; |
42 lua.call(fn,se,"__newindex",t,key,value); | 42 lua.call(fn,se,"__newindex",t,key,value); |
43 } | 43 } |
44 newindex(lua,h,key,value); | 44 newindex(lua,h,key,value); |
45 } | 45 } |
46 | 46 |