comparison core/src/luan/LuanState.java @ 517:8dcf9e12446b

add Luan.on_luan_close()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 27 May 2015 01:20:49 -0600
parents e3b0846dc2ef
children 8a217fe5b4f3
comparison
equal deleted inserted replaced
516:5752df8a67b5 517:8dcf9e12446b
11 public abstract class LuanState implements DeepCloneable { 11 public abstract class LuanState implements DeepCloneable {
12 12
13 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); 13 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
14 14
15 private Map registry; 15 private Map registry;
16 private final List<LuanFunction> onClose = new ArrayList<LuanFunction>();
16 17
17 protected LuanState() { 18 protected LuanState() {
18 registry = new HashMap(); 19 registry = new HashMap();
19 } 20 }
20 21
28 public abstract void setJava(); 29 public abstract void setJava();
29 public abstract LuanSource currentSource(); 30 public abstract LuanSource currentSource();
30 31
31 public final Map registry() { 32 public final Map registry() {
32 return registry; 33 return registry;
34 }
35
36 public void onClose(LuanFunction fn) {
37 onClose.add(fn);
38 }
39
40 public void close() throws LuanException {
41 for( LuanFunction fn : onClose ) {
42 call(fn);
43 }
44 onClose.clear();
33 } 45 }
34 46
35 public static LuanState newInstance() { 47 public static LuanState newInstance() {
36 return LuanCompiler.newLuanState(); 48 return LuanCompiler.newLuanState();
37 } 49 }