Explorar o código

[lua] Make sure to keep __class__ metadata for Std.is checks, and add inheritance checks for interfaces

Justin Donaldson %!s(int64=9) %!d(string=hai) anos
pai
achega
5c7189a78f
Modificáronse 1 ficheiros con 23 adicións e 4 borrados
  1. 23 4
      std/lua/Boot.hx

+ 23 - 4
std/lua/Boot.hx

@@ -126,10 +126,29 @@ class Boot {
 				return true;
 			default: {
 				if ( o!= null &&  Lua.type(o)  == "table" && Lua.type(cl) == "table"){
-					// first check if o is instance of cl
-					if (inheritsFrom(o, cl)) return true;
-
-					// do not use isClass/isEnum here, perform raw checks
+					var ro = o; // a reference to the object, descending recursively into the ancestors
+					while (ro != null){
+						var cls = getClass(ro); // make sure to getClass here, so that the genlua will keep the __class__ metatdata
+						if (cls == null) {
+							break; // no class for this, just break out.
+						} else if (cls == cl) {
+							return true; // class reference matches exactly, return true.
+						} else if (cls.__interfaces__ != null){
+							for (i in 1...(Table.maxn(cls.__interfaces__) + 1)){
+								// the class/interface shows up in the interface list, return true.
+								if (cls.__interfaces__[i] == cl) return true;
+							}
+						}
+
+						// Do some modifications to turn ro into a reference to its parent
+						// prototype, so that we can repeat these steps
+						ro = Lua.getmetatable(ro);
+						if (ro != null){
+							ro = ro.__index;
+						}
+					}
+					// We've exhausted standard inheritance checks.  Check for simple Class/Enum eqauality
+					// Also, do not use isClass/isEnum here, perform raw checks
 					untyped __feature__("Class.*",if( cl == Class && o.__name__ != null ) return true);
 					untyped __feature__("Enum.*",if( cl == Enum && o.__ename__ != null ) return true);
 					// last chance, is it an enum instance?