comparison core/src/luan/LuanTable.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
124 if( map==null ) 124 if( map==null )
125 return null; 125 return null;
126 return map.get(key); 126 return map.get(key);
127 } 127 }
128 128
129 public void put(Object key,Object val) { 129 public void put(LuanState luan,Object key,Object value) throws LuanException {
130 Object h = getHandler("__newindex");
131 if( h==null || rawGet(key)!=null ) {
132 rawPut(key,value);
133 return;
134 }
135 if( h instanceof LuanFunction ) {
136 LuanFunction fn = (LuanFunction)h;
137 luan.call(fn,"__newindex",new Object[]{this,key,value});
138 return;
139 }
140 if( h instanceof LuanMeta ) {
141 LuanMeta meta = (LuanMeta)h;
142 meta.__newindex(luan,this,key,value);
143 return;
144 }
145 if( h instanceof LuanTable ) {
146 LuanTable tbl = (LuanTable)h;
147 tbl.put(luan,key,value);
148 return;
149 }
150 throw luan.exception("invalid type "+Luan.type(h)+" for metamethod __newindex");
151 }
152
153 public void rawPut(Object key,Object val) {
130 Integer iT = Luan.asInteger(key); 154 Integer iT = Luan.asInteger(key);
131 if( iT != null ) { 155 if( iT != null ) {
132 int i = iT - 1; 156 int i = iT - 1;
133 if( list != null || i == 0 ) { 157 if( list != null || i == 0 ) {
134 if( i == list().size() ) { 158 if( i == list().size() ) {