Mercurial Hosting > luan
comparison core/src/luan/Luan.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 | e9d4d5854e54 |
children | 93e6e67768d7 |
comparison
equal
deleted
inserted
replaced
429:e3a6d9dbd694 | 430:f28320fd671d |
---|---|
106 Number n = (Number)obj; | 106 Number n = (Number)obj; |
107 int i = n.intValue(); | 107 int i = n.intValue(); |
108 return i==n.doubleValue() ? Integer.valueOf(i) : null; | 108 return i==n.doubleValue() ? Integer.valueOf(i) : null; |
109 } | 109 } |
110 | 110 |
111 public static String toString(Object obj) { | |
112 if( obj == null ) | |
113 return "nil"; | |
114 if( obj instanceof Number ) | |
115 return Luan.toString((Number)obj); | |
116 if( obj instanceof LuanException ) { | |
117 LuanException le = (LuanException)obj; | |
118 return le.getFullMessage(); | |
119 } | |
120 if( obj instanceof byte[] ) | |
121 return "binary: " + Integer.toHexString(obj.hashCode()); | |
122 return obj.toString(); | |
123 } | |
124 | |
125 public static String stringEncode(String s) { | 111 public static String stringEncode(String s) { |
126 s = s.replace("\\","\\\\"); | 112 s = s.replace("\\","\\\\"); |
127 s = s.replace("\u0007","\\a"); | 113 s = s.replace("\u0007","\\a"); |
128 s = s.replace("\b","\\b"); | 114 s = s.replace("\b","\\b"); |
129 s = s.replace("\f","\\f"); | 115 s = s.replace("\f","\\f"); |