Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/core/src/luan/LuanBit.java Sat May 02 20:13:24 2015 -0600 +++ b/core/src/luan/LuanBit.java Sat May 02 20:35:26 2015 -0600 @@ -90,18 +90,19 @@ public String toString(Object obj) throws LuanException { if( obj instanceof LuanTable ) { LuanTable tbl = (LuanTable)obj; - Object h = tbl.getHandler("__to_string"); - if( h instanceof LuanMeta ) { - LuanMeta meta = (LuanMeta)h; - return meta.__to_string(luan,tbl); - } - if( h != null ) { - LuanFunction fn = checkFunction(h); - if( fn != null ) - return checkString( Luan.first( call(fn,"__to_string",new Object[]{obj}) ) ); - } + return tbl.toString(luan); } - return Luan.toString(obj); + if( obj == null ) + return "nil"; + if( obj instanceof Number ) + return Luan.toString((Number)obj); + if( obj instanceof LuanException ) { + LuanException le = (LuanException)obj; + return le.getFullMessage(); + } + if( obj instanceof byte[] ) + return "binary: " + Integer.toHexString(obj.hashCode()); + return obj.toString(); } public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {