comparison core/src/luan/LuanBit.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 e3a6d9dbd694
children 93e6e67768d7
comparison
equal deleted inserted replaced
429:e3a6d9dbd694 430:f28320fd671d
88 } 88 }
89 89
90 public String toString(Object obj) throws LuanException { 90 public String toString(Object obj) throws LuanException {
91 if( obj instanceof LuanTable ) { 91 if( obj instanceof LuanTable ) {
92 LuanTable tbl = (LuanTable)obj; 92 LuanTable tbl = (LuanTable)obj;
93 Object h = tbl.getHandler("__to_string"); 93 return tbl.toString(luan);
94 if( h instanceof LuanMeta ) {
95 LuanMeta meta = (LuanMeta)h;
96 return meta.__to_string(luan,tbl);
97 }
98 if( h != null ) {
99 LuanFunction fn = checkFunction(h);
100 if( fn != null )
101 return checkString( Luan.first( call(fn,"__to_string",new Object[]{obj}) ) );
102 }
103 } 94 }
104 return Luan.toString(obj); 95 if( obj == null )
96 return "nil";
97 if( obj instanceof Number )
98 return Luan.toString((Number)obj);
99 if( obj instanceof LuanException ) {
100 LuanException le = (LuanException)obj;
101 return le.getFullMessage();
102 }
103 if( obj instanceof byte[] )
104 return "binary: " + Integer.toHexString(obj.hashCode());
105 return obj.toString();
105 } 106 }
106 107
107 public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException { 108 public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {
108 Object f = t.getHandler(op); 109 Object f = t.getHandler(op);
109 if( f == null ) 110 if( f == null )