405
|
1 package luan;
|
|
2
|
|
3 import java.util.Map;
|
|
4
|
|
5
|
|
6 public abstract class LuanMeta /*implements Iterable<Map.Entry<Object,Object>>*/ {
|
|
7
|
|
8 public abstract Object __index(LuanState luan,LuanTable tbl,Object key) throws LuanException;
|
|
9
|
|
10 // public abstract LuanFunction __pairs(LuanState luan,LuanTable tbl) throws LuanException;
|
|
11
|
|
12 public boolean canNewindex() {
|
|
13 return false;
|
|
14 }
|
|
15
|
|
16 public void __newindex(LuanState luan,LuanTable tbl,Object key,Object value) throws LuanException {
|
|
17 throw new UnsupportedOperationException();
|
|
18 }
|
|
19
|
|
20 public LuanTable newMetatable() {
|
|
21 LuanTable mt = new LuanTableImpl();
|
|
22 /*
|
|
23 try {
|
|
24 mt.put( "__index", new LuanJavaFunction(
|
|
25 LuanMeta.class.getMethod( "__index", LuanState.class, LuanTable.class, Object.class ), this
|
|
26 ) );
|
|
27 if( canNewindex() ) {
|
|
28 mt.put( "__newindex", new LuanJavaFunction(
|
|
29 LuanMeta.class.getMethod( "__newindex", LuanState.class, LuanTable.class, Object.class, Object.class ), mt
|
|
30 ) );
|
|
31 }
|
|
32 } catch(NoSuchMethodException e) {
|
|
33 throw new RuntimeException(e);
|
|
34 }
|
|
35 */
|
|
36 mt.put( "__index", this );
|
|
37 // mt.put( "__pairs", this );
|
|
38 if( canNewindex() )
|
|
39 mt.put( "__newindex", this );
|
|
40 return mt;
|
|
41 }
|
|
42
|
|
43 public LuanTable newTable() {
|
|
44 LuanTable tbl = new LuanTableImpl();
|
|
45 tbl.setMetatable( newMetatable() );
|
|
46 return tbl;
|
|
47 }
|
|
48 }
|