Mercurial Hosting > luan
comparison core/src/luan/LuanTable.java @ 430:f28320fd671d
fix LuanTable.toString() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 May 2015 20:35:26 -0600 |
parents | df95199ca4c0 |
children | 3ffe8ba5b297 |
comparison
equal
deleted
inserted
replaced
429:e3a6d9dbd694 | 430:f28320fd671d |
---|---|
86 return map==null || map.isEmpty(); | 86 return map==null || map.isEmpty(); |
87 } | 87 } |
88 | 88 |
89 public List<Object> asList() { | 89 public List<Object> asList() { |
90 return list!=null ? list : Collections.emptyList(); | 90 return list!=null ? list : Collections.emptyList(); |
91 } | |
92 | |
93 public String toString(LuanState luan) throws LuanException { | |
94 Object h = getHandler("__to_string"); | |
95 if( h == null ) | |
96 return rawToString(); | |
97 if( h instanceof LuanMeta ) { | |
98 LuanMeta meta = (LuanMeta)h; | |
99 return meta.__to_string(luan,this); | |
100 } | |
101 LuanFunction fn = luan.checkFunction(h); | |
102 return luan.checkString( Luan.first( luan.call(fn,"__to_string",new Object[]{this}) ) ); | |
103 } | |
104 | |
105 public String rawToString() { | |
106 return "table: " + Integer.toHexString(hashCode()); | |
91 } | 107 } |
92 | 108 |
93 public Object get(LuanState luan,Object key) throws LuanException { | 109 public Object get(LuanState luan,Object key) throws LuanException { |
94 Object value = rawGet(key); | 110 Object value = rawGet(key); |
95 if( value != null ) | 111 if( value != null ) |
350 map.put(entry.getKey(),entry.getValue()); | 366 map.put(entry.getKey(),entry.getValue()); |
351 } | 367 } |
352 return map; | 368 return map; |
353 } | 369 } |
354 | 370 |
355 @Override public final String toString() { | |
356 return "table: " + Integer.toHexString(hashCode()); | |
357 } | |
358 | |
359 } | 371 } |