diff --git a/hscript/Interp.hx b/hscript/Interp.hx index e7931c8..d6ef0cb 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -264,6 +264,7 @@ class Interp { return switch(Tools.expr(e2)) { + // TODO: type check for custom classes case EIdent("Class"): Std.isOfType(expr1, Class); case EIdent("Map") | EIdent("IMap"): @@ -280,7 +281,10 @@ class Interp { public function setVar(name:String, v:Dynamic):Void { if (_inCustomClass && _proxy.superClass != null) { - if (_proxy.superHasField(name)) { + if (_proxy.superIsCustomClass) { + cast(_proxy.superClass, CustomClass).hset(name, v); + } + else if (_proxy.superHasField(name)) { Reflect.setProperty(_proxy.superClass, name, v); } } @@ -1790,8 +1794,12 @@ class Interp { // Custom logic to handle super calls to prevent infinite recursion if(_inCustomClass) { // Force call super function. - if(o == _proxy.superClass) - return call(o, Reflect.field(_proxy.superClass, '_HX_SUPER__${f}'), args); + if(o == _proxy.superClass) { + if(_proxy.superIsCustomClass) + cast(_proxy.superClass, CustomClass).callFunction(f, args); + else + return call(o, Reflect.field(_proxy.superClass, '_HX_SUPER__${f}'), args); + } } else if (o is CustomClass) { _nextCallObject = null; diff --git a/hscript/customclass/CustomClass.hx b/hscript/customclass/CustomClass.hx index 30efd16..df8660c 100644 --- a/hscript/customclass/CustomClass.hx +++ b/hscript/customclass/CustomClass.hx @@ -27,6 +27,10 @@ class CustomClass implements IHScriptCustomAccessBehaviour { public var superClass:Dynamic; public var superConstructor(default, null):Dynamic; + public var superIsCustomClass(get, never):Bool; + private function get_superIsCustomClass():Bool + return (superClass != null && superClass is CustomClass); + public var className(get, never):String; private function get_className():String { return __class.toString(); @@ -41,8 +45,8 @@ class CustomClass implements IHScriptCustomAccessBehaviour { public var __allowSetGet:Bool = false; - private var isInline:Bool = false; - private var ogVariables:Map; + private var isInline(default, null):Bool = false; + private var ogVariables(default, null):Map; public function new(__class:CustomClassDecl, args:Array, ?extendFieldDecl:Map, ?ogInterp:Interp, ?callNew:Bool = true) { this.__class = __class; @@ -235,7 +239,7 @@ class CustomClass implements IHScriptCustomAccessBehaviour { // Field check private function hasField(name:String):Bool { - return __cachedFieldDecls != null ? __cachedFieldDecls.exists(name) : false; + return __cachedFieldDecls.exists(name); } private function getField(name:String):FieldDecl { @@ -243,15 +247,15 @@ class CustomClass implements IHScriptCustomAccessBehaviour { } private function hasVar(name:String):Bool { - return __cachedVarDecls != null ? __cachedVarDecls.exists(name) : false; + return __cachedVarDecls.exists(name); } private function getVar(name:String):VarDecl { - return __cachedVarDecls != null ? __cachedVarDecls.get(name) : null; + return __cachedVarDecls.get(name); } private function hasFunction(name:String):Bool { - return __cachedFunctionDecls != null ? __cachedFunctionDecls.exists(name) : false; + return __cachedFunctionDecls.exists(name); } private function getFunction(name:String):Function { @@ -277,6 +281,8 @@ class CustomClass implements IHScriptCustomAccessBehaviour { if (__superClassFieldList == null) { var realFields = Reflect.fields(superClass).concat(Type.getInstanceFields(Type.getClass(superClass))); __superClassFieldList = realFields; + + // TODO: macro-based superclass iteration for Custom Class as superclass } return __superClassFieldList.indexOf(name) != -1;