comparison core/src/luan/LuanState.java @ 221:ec016471c6eb

make LuanTable an interface git-svn-id: https://luan-java.googlecode.com/svn/trunk@222 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 17 Jul 2014 07:49:26 +0000
parents 5ba136769034
children 05eb2837ddbf
comparison
equal deleted inserted replaced
220:61afe2a1ce96 221:ec016471c6eb
17 17
18 public abstract class LuanState implements DeepCloneable<LuanState> { 18 public abstract class LuanState implements DeepCloneable<LuanState> {
19 19
20 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); 20 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
21 21
22 private LuanTable registry; 22 private LuanTableImpl registry;
23 private LuanTable global; 23 private LuanTableImpl global;
24 private LuanTable metatable; // generic metatable 24 private LuanTableImpl metatable; // generic metatable
25 25
26 protected LuanState() { 26 protected LuanState() {
27 registry = new LuanTable(); 27 registry = new LuanTableImpl();
28 global = new LuanTable(); 28 global = new LuanTableImpl();
29 global.put("_G",global); 29 global.put("_G",global);
30 metatable = newMetatable(); 30 metatable = newMetatable();
31 } 31 }
32 32
33 protected LuanState(LuanState luan) {} 33 protected LuanState(LuanState luan) {}
45 } 45 }
46 46
47 public final LuanTable registryTable(Object key) { 47 public final LuanTable registryTable(Object key) {
48 LuanTable tbl = (LuanTable)registry.get(key); 48 LuanTable tbl = (LuanTable)registry.get(key);
49 if( tbl == null ) { 49 if( tbl == null ) {
50 tbl = new LuanTable(); 50 tbl = new LuanTableImpl();
51 registry.put(key,tbl); 51 registry.put(key,tbl);
52 } 52 }
53 return tbl; 53 return tbl;
54 } 54 }
55 55
66 throw new RuntimeException(e); 66 throw new RuntimeException(e);
67 } 67 }
68 } 68 }
69 69
70 public final Object eval(String cmd) { 70 public final Object eval(String cmd) {
71 return eval(cmd,new LuanTable()); 71 return eval(cmd,new LuanTableImpl());
72 } 72 }
73 73
74 public final Object eval(String cmd,LuanTable env) { 74 public final Object eval(String cmd,LuanTable env) {
75 try { 75 try {
76 LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true); 76 LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true);
97 public final Object getHandler(String op,Object obj) { 97 public final Object getHandler(String op,Object obj) {
98 LuanTable t = getMetatable(obj); 98 LuanTable t = getMetatable(obj);
99 return t==null ? null : t.get(op); 99 return t==null ? null : t.get(op);
100 } 100 }
101 101
102 private static LuanTable newMetatable() { 102 private static LuanTableImpl newMetatable() {
103 LuanTable metatable = new LuanTable(); 103 LuanTableImpl metatable = new LuanTableImpl();
104 try { 104 try {
105 metatable.put( "__index", new LuanJavaFunction( 105 metatable.put( "__index", new LuanJavaFunction(
106 LuanState.class.getMethod("__index",LuanState.class,Object.class,Object.class), null 106 LuanState.class.getMethod("__index",LuanState.class,Object.class,Object.class), null
107 ) ); 107 ) );
108 metatable.put( "__newindex", new LuanJavaFunction( 108 metatable.put( "__newindex", new LuanJavaFunction(