comparison core/src/luan/LuanState.java @ 672:d3e5414bdf4c

better java permission handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Apr 2016 17:03:30 -0600
parents 8e8c30b72e9b
children b620b8e1010f
comparison
equal deleted inserted replaced
671:82f130eba7b0 672:d3e5414bdf4c
11 import luan.impl.LuanCompiler; 11 import luan.impl.LuanCompiler;
12 import luan.modules.BasicLuan; 12 import luan.modules.BasicLuan;
13 import luan.modules.JavaLuan; 13 import luan.modules.JavaLuan;
14 14
15 15
16 public abstract class LuanState implements DeepCloneable { 16 public final class LuanState implements DeepCloneable {
17 17
18 public LuanJava java;
18 private Map registry; 19 private Map registry;
19 private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>(); 20 private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
20 21
21 protected LuanState() { 22 public LuanState() {
23 java = new LuanJava();
22 registry = new HashMap(); 24 registry = new HashMap();
23 } 25 }
24 26
25 protected LuanState(LuanState luan) {} 27 private LuanState(LuanState luan) {}
26 28
27 @Override public void deepenClone(DeepCloneable clone,DeepCloner cloner) { 29 @Override public LuanState shallowClone() {
28 ((LuanState)clone).registry = cloner.deepClone(registry); 30 return new LuanState(this);
29 } 31 }
30 32
31 public abstract boolean hasJava(); 33 @Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
32 public abstract void setJava(); 34 LuanState clone = (LuanState)dc;
35 clone.registry = cloner.deepClone(registry);
36 clone.java = (LuanJava)cloner.deepClone(java);
37 }
33 38
34 public final Map registry() { 39 public final Map registry() {
35 return registry; 40 return registry;
36 } 41 }
37 42
44 Closeable c = ref.get(); 49 Closeable c = ref.get();
45 if( c != null ) 50 if( c != null )
46 c.close(); 51 c.close();
47 } 52 }
48 onClose.clear(); 53 onClose.clear();
49 }
50
51 public static LuanState newInstance() {
52 return LuanCompiler.newLuanState();
53 } 54 }
54 55
55 public final Object eval(String cmd) throws LuanException { 56 public final Object eval(String cmd) throws LuanException {
56 return eval(cmd,new LuanTable()); 57 return eval(cmd,new LuanTable());
57 } 58 }
79 public Object index(Object obj,Object key) throws LuanException { 80 public Object index(Object obj,Object key) throws LuanException {
80 if( obj instanceof LuanTable ) { 81 if( obj instanceof LuanTable ) {
81 LuanTable tbl = (LuanTable)obj; 82 LuanTable tbl = (LuanTable)obj;
82 return tbl.get(this,key); 83 return tbl.get(this,key);
83 } 84 }
84 if( obj != null && hasJava() ) 85 if( obj != null && java.ok )
85 return JavaLuan.__index(this,obj,key,false); 86 return JavaLuan.__index(this,obj,key,false);
86 throw new LuanException("attempt to index a " + Luan.type(obj) + " value" ); 87 throw new LuanException("attempt to index a " + Luan.type(obj) + " value" );
87 } 88 }
88 89
89 /* 90 /*