comparison core/src/luan/modules/BasicLuan.java @ 471:f3a24435d04d

add support for __metatable
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 May 2015 00:12:42 -0600
parents 2e79b47d02a2
children bab5607a0eed
comparison
equal deleted inserted replaced
470:5627eb637eb4 471:f3a24435d04d
67 return new Object[]{i,val}; 67 return new Object[]{i,val};
68 } 68 }
69 }; 69 };
70 } 70 }
71 71
72 public static LuanTable get_metatable(LuanTable table) { 72 public static Object get_metatable(LuanTable table) {
73 return table.getMetatable(); 73 LuanTable metatable = table.getMetatable();
74 } 74 if( metatable == null )
75 75 return null;
76 public static LuanTable set_metatable(LuanTable table,LuanTable metatable) { 76 Object obj = metatable.rawGet("__metatable");
77 return obj!=null ? obj : metatable;
78 }
79
80 public static LuanTable set_metatable(LuanState luan,LuanTable table,LuanTable metatable) throws LuanException {
81 if( table.getHandler("__metatable") != null )
82 throw luan.exception("cannot change a protected metatable");
77 table.setMetatable(metatable); 83 table.setMetatable(metatable);
78 return table; 84 return table;
79 } 85 }
80 86
81 public static boolean raw_equal(Object v1,Object v2) { 87 public static boolean raw_equal(Object v1,Object v2) {