comparison core/src/luan/modules/BasicLuan.java @ 422:af82b266fe89

add Io.repr()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 16:13:52 -0600
parents 8fbb961aabd5
children 1eafb11a150d
comparison
equal deleted inserted replaced
421:b31d614343e8 422:af82b266fe89
218 218
219 private LuanFunction fn(Object obj) { 219 private LuanFunction fn(Object obj) {
220 return obj instanceof LuanFunction ? (LuanFunction)obj : null; 220 return obj instanceof LuanFunction ? (LuanFunction)obj : null;
221 } 221 }
222 222
223 public static void try_(LuanState luan,LuanTable blocks) throws LuanException { 223 public static Object try_(LuanState luan,LuanTable blocks) throws LuanException {
224 Utils.checkNotNull(luan,blocks); 224 Utils.checkNotNull(luan,blocks);
225 Object obj = blocks.get(1); 225 Object obj = blocks.get(1);
226 if( obj == null ) 226 if( obj == null )
227 throw luan.exception("missing 'try' value"); 227 throw luan.exception("missing 'try' value");
228 if( !(obj instanceof LuanFunction) ) 228 if( !(obj instanceof LuanFunction) )
241 if( !(obj instanceof LuanFunction) ) 241 if( !(obj instanceof LuanFunction) )
242 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")"); 242 throw luan.exception("bad 'finally' value (function expected, got "+Luan.type(obj)+")");
243 finallyFn = (LuanFunction)obj; 243 finallyFn = (LuanFunction)obj;
244 } 244 }
245 try { 245 try {
246 luan.call(tryFn); 246 return luan.call(tryFn);
247 } catch(LuanException e) { 247 } catch(LuanException e) {
248 if( catchFn == null ) 248 if( catchFn == null )
249 throw e; 249 throw e;
250 luan.call(catchFn,new Object[]{e}); 250 return luan.call(catchFn,new Object[]{e});
251 } finally { 251 } finally {
252 if( finallyFn != null ) 252 if( finallyFn != null )
253 luan.call(finallyFn); 253 luan.call(finallyFn);
254 } 254 }
255 } 255 }