Public vars for Custom Classes in scripts

Uses public variables from the same scope as where the class was defined.
This commit is contained in:
Jaime Humberto Macias Bustamante
2025-04-08 11:48:31 -07:00
parent 65b43ebe78
commit d055203559
4 changed files with 24 additions and 6 deletions
+2
View File
@@ -222,6 +222,8 @@ typedef VarDecl = {
var type : Null<CType>;
}
typedef TypeParamDecl = {};
enum EnumType {
ESimple(name: String);
EConstructor(name: String, args: Array<Argument>);
+4 -2
View File
@@ -804,7 +804,7 @@ class Interp {
if (customClasses.exists(name))
error(EAlreadyExistingClass(name));
trace("WARNING: Old Custom Class system marked for removal.\n'newCustomClass = true' to use the new system (EXPERIMENTAL)");
trace("WARNING: Old Custom Class system marked for removal.\n'newCustomClass = true' to use the new system (STILL IN DEVELOPMENT)");
customClasses.set(name, new CustomClassHandler(this, name, fields, importVar(extend), [for (i in interfaces) importVar(i)]));
return null;
}
@@ -877,7 +877,9 @@ class Interp {
classDecl: classDecl,
imports: localImports,
usings: [for(u in this.usings) u.name],
pkg: null
pkg: null,
ogInterp: this,
usePublicVars: true
};
registerCustomClass(customClassDecl, null);
+5 -1
View File
@@ -44,12 +44,16 @@ class CustomClass implements IHScriptCustomAccessBehaviour {
this.__class = __class;
this.interp = new Interp(this);
if (ogInterp != null && ogInterp.importFailedCallback != null && ogInterp.errorHandler != null) {
if (ogInterp != null) {
interp.importFailedCallback = ogInterp.importFailedCallback;
interp.errorHandler = ogInterp.errorHandler;
interp.allowStaticVariables = ogInterp.allowStaticVariables;
interp.staticVariables = ogInterp.staticVariables;
// todo: make it so you can use variables from the same scope as where the class was defined
if(__class.usePublicVars) {
interp.allowPublicVariables = __class.staticInterp.allowPublicVariables;
interp.publicVariables = __class.staticInterp.publicVariables;
}
}
buildImports();
+13 -3
View File
@@ -14,7 +14,8 @@ class CustomClassDecl implements IHScriptCustomAccessBehaviour {
public var imports:Map<String, CustomClassImport>;
public var usings:Array<String>;
public var pkg:Null<Array<String>> = null;
public var ogInterp:Interp = null;
public var ogInterp:Null<Interp> = null;
public var usePublicVars:Null<Bool> = null;
public var staticInterp:Interp = new Interp();
@@ -26,18 +27,27 @@ class CustomClassDecl implements IHScriptCustomAccessBehaviour {
public var __allowSetGet:Bool = true;
public function new(classDecl:Expr.ClassDecl, imports:Map<String, CustomClassImport>, usings:Array<String>, pkg:Null<Array<String>>, ogInterp:Interp = null) {
public function new(classDecl:Expr.ClassDecl, imports:Map<String, CustomClassImport>, usings:Array<String>, ?pkg:Array<String>, ?ogInterp:Interp, ?usePublicVars:Bool) {
this.classDecl = classDecl;
this.imports = imports;
this.usings = usings;
this.pkg = pkg;
this.ogInterp = ogInterp;
this.usePublicVars = usePublicVars;
if(ogInterp != null && ogInterp.importFailedCallback != null && ogInterp.errorHandler != null) {
if(ogInterp != null) {
staticInterp.importFailedCallback = ogInterp.importFailedCallback;
staticInterp.errorHandler = ogInterp.errorHandler;
staticInterp.allowStaticVariables = ogInterp.allowStaticVariables;
staticInterp.staticVariables = ogInterp.staticVariables;
if(usePublicVars != null && usePublicVars) {
// uses public variables from the same scope as where the class was defined
staticInterp.allowPublicVariables = ogInterp.allowPublicVariables;
staticInterp.publicVariables = ogInterp.publicVariables;
}
// TODO: use normal variables, not just public
}
cacheImports();