This commit is contained in:
Jaime Humberto Macias Bustamante
2025-06-17 15:27:21 -07:00
parent 04a50580c6
commit 6441acc93d
3 changed files with 28 additions and 24 deletions
+26 -6
View File
@@ -33,14 +33,14 @@ class CustomClass implements IHScriptCustomClassBehaviour {
var __constructor:Function;
var fields:Array<Expr>;
public function new(__class:CustomClassHandler, args:Array<Dynamic>) {
public function new(__class:CustomClassHandler, ?args:Array<Dynamic>) {
this.__class = __class;
__interp = new Interp();
__interp.errorHandler = __class.staticInterp.errorHandler;
__interp.importFailedCallback = __class.staticInterp.importFailedCallback;
__interp.variables = __class.staticInterp.variables; // This will access to static fields
// __interp.variables = __class.staticInterp.variables;
__interp.publicVariables = __class.ogInterp.publicVariables;
__interp.staticVariables = __class.ogInterp.staticVariables;
@@ -56,6 +56,11 @@ class CustomClass implements IHScriptCustomClassBehaviour {
@:privateAccess __interp.exprReturn(f);
}
for (f => v in __class.staticInterp.variables) {
if (!__interp.variables.exists(f))
__interp.variables.set(f, v);
}
__interp.scriptObject = this;
if (hasField('new')) {
@@ -105,10 +110,13 @@ class CustomClass implements IHScriptCustomClassBehaviour {
}
function hasField(name:String) {
// return __interp.variables.exists(name);
return __class__fields.contains(name);
}
function hasStaticField(name:String):Bool {
return __class.hasField(name);
}
function getField(name:String, allowProperty:Bool = true):Dynamic {
var f = __interp.variables.get(name);
if (allowProperty && f is Property) {
@@ -146,12 +154,19 @@ class CustomClass implements IHScriptCustomClassBehaviour {
public function hget(name:String):Dynamic {
switch (name) {
case 'superClass': return __superClass;
case 'superConstructor': return __constructor;
case 'superClass':
return __superClass;
case 'superConstructor':
return __constructor;
default:
if (hasField(name))
if (hasField(name))
return getField(name);
if (hasStaticField(name)) {
__interp.error(ECustom('The field ${name} should be accessed in a static way.'));
return null;
}
if (__superClass != null) {
if (superHasField(name)) {
__superClass.__allowSetGet = this.__allowSetGet;
@@ -174,6 +189,11 @@ class CustomClass implements IHScriptCustomClassBehaviour {
return setField(name, val);
}
if (hasStaticField(name)) {
__interp.error(ECustom('The field ${name} should be accessed in a static way.'));
return null;
}
if (__superClass != null) {
if (superHasField(name)) {
__superClass.__allowSetGet = this.__allowSetGet;
+2 -4
View File
@@ -23,7 +23,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
public var cl:Dynamic;
private var staticInterp:Interp;
private var staticFields:Array<String>;
private var staticFields:Array<String> = [];
public function new(ogInterp:Interp, name:String, fields:Array<Expr>, ?extend:String, ?interfaces:Array<String>) {
this.ogInterp = ogInterp;
@@ -200,9 +200,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
*/
// I can't believe all these lines of code above got reduced to this sentence.
var _class = new CustomClass(this, args);
return _class;
return new CustomClass(this, args);
}
@:allow(hscript.Interp)
-14
View File
@@ -1280,13 +1280,6 @@ class Interp {
if (o == null)
error(EInvalidAccess(f));
if(o is CustomClass) {
if(cast(o, CustomClass).__class.hasField(f)) {
var clsName = cast(o, CustomClass).className;
error(ECustom('The field ${clsName}.${f} should be accessed in a static way.'));
}
}
var cls = Type.getClass(o);
if (useRedirects && {
var cl:Null<String> = getClassType(o, cls);
@@ -1327,13 +1320,6 @@ class Interp {
if (o == null)
error(EInvalidAccess(f));
if(o is CustomClass) {
if(cast(o, CustomClass).__class.hasField(f)) {
var clsName = cast(o, CustomClass).className;
error(ECustom('The field ${clsName}.${f} should be accessed in a static way.'));
}
}
if (useRedirects && {
var cl:Null<String> = getClassType(o);
cl != null && setRedirects.exists(cl) && (_setRedirect = setRedirects[cl]) != null;