Mercurial Hosting > luan
comparison core/src/luan/LuanPropertyMeta.java @ 426:23a93c118042
fix LuanTable.get() to use metatables
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 18:44:20 -0600 |
parents | 91af5337b9ae |
children | dae264ad6a7b |
comparison
equal
deleted
inserted
replaced
425:0a2fb80907f9 | 426:23a93c118042 |
---|---|
8 public static final LuanPropertyMeta INSTANCE = new LuanPropertyMeta(); | 8 public static final LuanPropertyMeta INSTANCE = new LuanPropertyMeta(); |
9 | 9 |
10 private LuanPropertyMeta() {} | 10 private LuanPropertyMeta() {} |
11 | 11 |
12 public LuanTable getters(LuanTable tbl) { | 12 public LuanTable getters(LuanTable tbl) { |
13 return (LuanTable)tbl.getMetatable().get("get"); | 13 return (LuanTable)tbl.getMetatable().rawGet("get"); |
14 } | 14 } |
15 | 15 |
16 public LuanTable setters(LuanTable tbl) { | 16 public LuanTable setters(LuanTable tbl) { |
17 return (LuanTable)tbl.getMetatable().get("set"); | 17 return (LuanTable)tbl.getMetatable().rawGet("set"); |
18 } | 18 } |
19 | 19 |
20 protected String type(LuanTable tbl) { | 20 protected String type(LuanTable tbl) { |
21 return (String)tbl.getMetatable().get("type"); | 21 return (String)tbl.getMetatable().rawGet("type"); |
22 } | 22 } |
23 | 23 |
24 @Override public Object __index(LuanState luan,LuanTable tbl,Object key) throws LuanException { | 24 @Override public Object __index(LuanState luan,LuanTable tbl,Object key) throws LuanException { |
25 Object obj = getters(tbl).get(key); | 25 Object obj = getters(tbl).rawGet(key); |
26 if( obj == null ) | 26 if( obj == null ) |
27 return null; | 27 return null; |
28 if( !(obj instanceof LuanFunction) ) | 28 if( !(obj instanceof LuanFunction) ) |
29 throw luan.exception("get for '"+key+"' isn't a function"); | 29 throw luan.exception("get for '"+key+"' isn't a function"); |
30 LuanFunction fn = (LuanFunction)obj; | 30 LuanFunction fn = (LuanFunction)obj; |
51 @Override public boolean canNewindex() { | 51 @Override public boolean canNewindex() { |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 @Override public void __newindex(LuanState luan,LuanTable tbl,Object key,Object value) throws LuanException { | 55 @Override public void __newindex(LuanState luan,LuanTable tbl,Object key,Object value) throws LuanException { |
56 Object obj = setters(tbl).get(key); | 56 Object obj = setters(tbl).rawGet(key); |
57 if( obj == null ) | 57 if( obj == null ) |
58 throw luan.exception("can't set property '"+key+"'"); | 58 throw luan.exception("can't set property '"+key+"'"); |
59 if( !(obj instanceof LuanFunction) ) | 59 if( !(obj instanceof LuanFunction) ) |
60 throw luan.exception("set for '"+key+"' isn't a function"); | 60 throw luan.exception("set for '"+key+"' isn't a function"); |
61 LuanFunction fn = (LuanFunction)obj; | 61 LuanFunction fn = (LuanFunction)obj; |