comparison core/src/luan/modules/BasicLuan.java @ 502:d3183a330ff5

improve the __index metamethod to work with any type; simplify luan_proxy to eliminate base;
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 May 2015 17:57:20 -0600
parents 4dc9cb26a3a8
children 8dcf9e12446b
comparison
equal deleted inserted replaced
501:f26485a3692c 502:d3183a330ff5
62 return new Object[]{i,val}; 62 return new Object[]{i,val};
63 } 63 }
64 }; 64 };
65 } 65 }
66 66
67 public static Object get_metatable(LuanTable table) { 67 public static Object get_metatable(LuanState luan,LuanTable table) throws LuanException {
68 Utils.checkNotNull(luan,table);
68 LuanTable metatable = table.getMetatable(); 69 LuanTable metatable = table.getMetatable();
69 if( metatable == null ) 70 if( metatable == null )
70 return null; 71 return null;
71 Object obj = metatable.rawGet("__metatable"); 72 Object obj = metatable.rawGet("__metatable");
72 return obj!=null ? obj : metatable; 73 return obj!=null ? obj : metatable;
73 } 74 }
74 75
75 public static void set_metatable(LuanState luan,LuanTable table,LuanTable metatable) throws LuanException { 76 public static void set_metatable(LuanState luan,LuanTable table,LuanTable metatable) throws LuanException {
77 Utils.checkNotNull(luan,table);
76 if( table.getHandler("__metatable") != null ) 78 if( table.getHandler("__metatable") != null )
77 throw luan.exception("cannot change a protected metatable"); 79 throw luan.exception("cannot change a protected metatable");
78 table.setMetatable(metatable); 80 table.setMetatable(metatable);
79 } 81 }
80 82