Mercurial Hosting > luan
comparison src/luan/LuanTable.java @ 796:6b8ea0a9b7c9
remove LuanMeta
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 05 Sep 2016 19:52:49 -0600 |
parents | d69d3c51c44e |
children | 2443152dc2f1 |
comparison
equal
deleted
inserted
replaced
795:dd36eae6aa04 | 796:6b8ea0a9b7c9 |
---|---|
115 | 115 |
116 public String toString(LuanState luan) throws LuanException { | 116 public String toString(LuanState luan) throws LuanException { |
117 Object h = getHandler("__to_string"); | 117 Object h = getHandler("__to_string"); |
118 if( h == null ) | 118 if( h == null ) |
119 return rawToString(); | 119 return rawToString(); |
120 if( h instanceof LuanMeta ) { | |
121 LuanMeta meta = (LuanMeta)h; | |
122 return meta.__to_string(luan,this); | |
123 } | |
124 LuanFunction fn = Luan.checkFunction(h); | 120 LuanFunction fn = Luan.checkFunction(h); |
125 return Luan.checkString( Luan.first( fn.call(luan,new Object[]{this}) ) ); | 121 return Luan.checkString( Luan.first( fn.call(luan,new Object[]{this}) ) ); |
126 } | 122 } |
127 | 123 |
128 public String rawToString() { | 124 public String rawToString() { |
138 return null; | 134 return null; |
139 if( h instanceof LuanFunction ) { | 135 if( h instanceof LuanFunction ) { |
140 LuanFunction fn = (LuanFunction)h; | 136 LuanFunction fn = (LuanFunction)h; |
141 return Luan.first(fn.call(luan,new Object[]{this,key})); | 137 return Luan.first(fn.call(luan,new Object[]{this,key})); |
142 } | 138 } |
143 if( h instanceof LuanMeta ) { | |
144 LuanMeta meta = (LuanMeta)h; | |
145 return meta.__index(luan,this,key); | |
146 } | |
147 return luan.index(h,key); | 139 return luan.index(h,key); |
148 } | 140 } |
149 | 141 |
150 public Object rawGet(Object key) { | 142 public Object rawGet(Object key) { |
151 check(); | 143 check(); |
173 return; | 165 return; |
174 } | 166 } |
175 if( h instanceof LuanFunction ) { | 167 if( h instanceof LuanFunction ) { |
176 LuanFunction fn = (LuanFunction)h; | 168 LuanFunction fn = (LuanFunction)h; |
177 fn.call(luan,new Object[]{this,key,value}); | 169 fn.call(luan,new Object[]{this,key,value}); |
178 return; | |
179 } | |
180 if( h instanceof LuanMeta ) { | |
181 LuanMeta meta = (LuanMeta)h; | |
182 meta.__new_index(luan,this,key,value); | |
183 return; | 170 return; |
184 } | 171 } |
185 if( h instanceof LuanTable ) { | 172 if( h instanceof LuanTable ) { |
186 LuanTable tbl = (LuanTable)h; | 173 LuanTable tbl = (LuanTable)h; |
187 tbl.put(luan,key,value); | 174 tbl.put(luan,key,value); |
352 Object obj = Luan.first(fn.call(luan,new Object[]{this})); | 339 Object obj = Luan.first(fn.call(luan,new Object[]{this})); |
353 if( !(obj instanceof LuanFunction) ) | 340 if( !(obj instanceof LuanFunction) ) |
354 throw new LuanException( "metamethod __pairs should return function but returned " + Luan.type(obj) ); | 341 throw new LuanException( "metamethod __pairs should return function but returned " + Luan.type(obj) ); |
355 return (LuanFunction)obj; | 342 return (LuanFunction)obj; |
356 } | 343 } |
357 if( h instanceof LuanMeta ) { | |
358 LuanMeta meta = (LuanMeta)h; | |
359 return meta.__pairs(luan,this); | |
360 } | |
361 throw new LuanException( "invalid type of metamethod __pairs: " + Luan.type(h) ); | 344 throw new LuanException( "invalid type of metamethod __pairs: " + Luan.type(h) ); |
362 } | 345 } |
363 return rawPairs(); | 346 return rawPairs(); |
364 } | 347 } |
365 | 348 |