Mercurial Hosting > luan
diff core/src/luan/LuanState.java @ 527:ef0336efe33c
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 May 2015 03:29:04 -0600 |
parents | 8a217fe5b4f3 |
children | f1601a4ce1aa |
line wrap: on
line diff
--- a/core/src/luan/LuanState.java Wed May 27 03:20:38 2015 -0600 +++ b/core/src/luan/LuanState.java Wed May 27 03:29:04 2015 -0600 @@ -1,5 +1,7 @@ package luan; +import java.io.Closeable; +import java.io.IOException; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.util.List; @@ -15,7 +17,7 @@ final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); private Map registry; - private final List<Reference<Runnable>> onClose = new ArrayList<Reference<Runnable>>(); + private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>(); protected LuanState() { registry = new HashMap(); @@ -35,15 +37,15 @@ return registry; } - public void onClose(Runnable fn) { - onClose.add(new WeakReference<Runnable>(fn)); + public void onClose(Closeable c) { + onClose.add(new WeakReference<Closeable>(c)); } - public void close() { - for( Reference<Runnable> ref : onClose ) { - Runnable r = ref.get(); - if( r != null ) - r.run(); + public void close() throws IOException { + for( Reference<Closeable> ref : onClose ) { + Closeable c = ref.get(); + if( c != null ) + c.close(); } onClose.clear(); }