Mercurial Hosting > luan
comparison core/src/luan/impl/SetTableEntry.java @ 427:dae264ad6a7b
fix LuanTable.put() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 19:29:07 -0600 |
parents | 23a93c118042 |
children | df95199ca4c0 |
comparison
equal
deleted
inserted
replaced
426:23a93c118042 | 427:dae264ad6a7b |
---|---|
23 newindex( luan, tableExpr.eval(luan), keyExpr.eval(luan), value ); | 23 newindex( luan, tableExpr.eval(luan), keyExpr.eval(luan), value ); |
24 } | 24 } |
25 | 25 |
26 private void newindex(LuanStateImpl luan,Object t,Object key,Object value) throws LuanException { | 26 private void newindex(LuanStateImpl luan,Object t,Object key,Object value) throws LuanException { |
27 if( t instanceof LuanTable ) { | 27 if( t instanceof LuanTable ) { |
28 LuanTable table = (LuanTable)t; | 28 LuanTable tbl = (LuanTable)t; |
29 Object h = table.getHandler("__newindex"); | 29 tbl.put(luan,key,value); |
30 if( h==null || table.rawGet(key)!=null ) { | 30 return; |
31 try { | |
32 table.put(key,value); | |
33 } catch(IllegalArgumentException e) { | |
34 throw luan.bit(se).exception(e); | |
35 } catch(UnsupportedOperationException e) { | |
36 throw luan.bit(se).exception(e); | |
37 } | |
38 return; | |
39 } | |
40 if( h instanceof LuanFunction ) { | |
41 LuanFunction fn = (LuanFunction)h; | |
42 luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value}); | |
43 return; | |
44 } | |
45 if( h instanceof LuanMeta ) { | |
46 LuanMeta meta = (LuanMeta)h; | |
47 meta.__newindex(luan,table,key,value); | |
48 return; | |
49 } | |
50 newindex(luan,h,key,value); | |
51 } | 31 } |
52 if( t != null && luan.currentEnvironment().hasJava() ) | 32 if( t != null && luan.currentEnvironment().hasJava() ) |
53 JavaLuan.__newindex(luan,t,key,value); | 33 JavaLuan.__newindex(luan,t,key,value); |
54 else | 34 else |
55 throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); | 35 throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); |