changeset 471:f3a24435d04d

add support for __metatable
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 May 2015 00:12:42 -0600
parents 5627eb637eb4
children f4aca5a5346a
files core/src/luan/modules/BasicLuan.java
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/modules/BasicLuan.java	Sat May 09 23:54:22 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Sun May 10 00:12:42 2015 -0600
@@ -69,11 +69,17 @@
 		};
 	}
 
-	public static LuanTable get_metatable(LuanTable table) {
-		return table.getMetatable();
+	public static Object get_metatable(LuanTable table) {
+		LuanTable metatable = table.getMetatable();
+		if( metatable == null )
+			return null;
+		Object obj = metatable.rawGet("__metatable");
+		return obj!=null ? obj : metatable;
 	}
 
-	public static LuanTable set_metatable(LuanTable table,LuanTable metatable) {
+	public static LuanTable set_metatable(LuanState luan,LuanTable table,LuanTable metatable) throws LuanException {
+		if( table.getHandler("__metatable") != null )
+			throw luan.exception("cannot change a protected metatable");
 		table.setMetatable(metatable);
 		return table;
 	}