From 70efab47d12faab0dc9e7c9bf6575ca1bc8c3241 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Mon, 14 Jul 2025 12:59:54 -0700 Subject: [PATCH] Documentation + custom classes import alias --- hscript/IHScriptAbstractBehaviour.hx | 2 +- hscript/IHScriptCustomAccessBehaviour.hx | 3 +++ hscript/IHScriptCustomBehaviour.hx | 17 +++++++++++++++++ hscript/IHScriptCustomClassBehaviour.hx | 3 +++ hscript/IHScriptCustomConstructor.hx | 3 +++ hscript/Interp.hx | 15 +++++++++++---- hscript/Tools.hx | 3 +++ 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/hscript/IHScriptAbstractBehaviour.hx b/hscript/IHScriptAbstractBehaviour.hx index c091e7f..96f8919 100644 --- a/hscript/IHScriptAbstractBehaviour.hx +++ b/hscript/IHScriptAbstractBehaviour.hx @@ -1,7 +1,7 @@ package hscript; // Soon... -interface IHScriptAbstractBehaviour { +interface IHScriptAbstractBehaviour extends IHScriptCustomBehaviour { public var hasOp:Bool; public var hasArr:Bool; // @:op(A * B), @:op(A++), etc... diff --git a/hscript/IHScriptCustomAccessBehaviour.hx b/hscript/IHScriptCustomAccessBehaviour.hx index 363d9fe..d73a24d 100644 --- a/hscript/IHScriptCustomAccessBehaviour.hx +++ b/hscript/IHScriptCustomAccessBehaviour.hx @@ -1,5 +1,8 @@ package hscript; +/** + * Same Interface as IHScriptCustomBehaviour but for Property. + */ interface IHScriptCustomAccessBehaviour extends IHScriptCustomBehaviour { var __allowSetGet:Bool; diff --git a/hscript/IHScriptCustomBehaviour.hx b/hscript/IHScriptCustomBehaviour.hx index 9a3cf1a..bc94d3a 100644 --- a/hscript/IHScriptCustomBehaviour.hx +++ b/hscript/IHScriptCustomBehaviour.hx @@ -1,6 +1,23 @@ package hscript; +/** + * Special Interface for handling field access behaviour. + * Basically works like the operator overload `@:op(a.b)` + * for an abstract. + */ interface IHScriptCustomBehaviour { + /** + * Field Write Access + * @param name - Field Name + * @param val - Value to assign + * @return Dynamic - The assigned value + */ public function hset(name:String, val:Dynamic):Dynamic; + + /** + * Field Read Access + * @param name - Field Name + * @return Dynamic - The returned field + */ public function hget(name:String):Dynamic; } \ No newline at end of file diff --git a/hscript/IHScriptCustomClassBehaviour.hx b/hscript/IHScriptCustomClassBehaviour.hx index 9a2711e..4d2e683 100644 --- a/hscript/IHScriptCustomClassBehaviour.hx +++ b/hscript/IHScriptCustomClassBehaviour.hx @@ -1,5 +1,8 @@ package hscript; +/** + * Special Interface to make a class usable for Custom Classes. + */ interface IHScriptCustomClassBehaviour extends IHScriptCustomAccessBehaviour{ public var __interp:Interp; public var __real_fields:Array; diff --git a/hscript/IHScriptCustomConstructor.hx b/hscript/IHScriptCustomConstructor.hx index 89e635d..c65f9cb 100644 --- a/hscript/IHScriptCustomConstructor.hx +++ b/hscript/IHScriptCustomConstructor.hx @@ -1,5 +1,8 @@ package hscript; +/** + * Special Interface for handling new instances of an object. + */ interface IHScriptCustomConstructor { public function hnew(args:Array):Dynamic; } \ No newline at end of file diff --git a/hscript/Interp.hx b/hscript/Interp.hx index 8b5d462..1486892 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -138,6 +138,7 @@ class Interp { var returnValue:Dynamic; var isBypassAccessor:Bool = false; + var setAlias:Null = null; // Custom Class import alias public var importEnabled:Bool = true; @@ -701,8 +702,10 @@ class Interp { #end switch (e) { case EClass(name, fields, extend, interfaces): - if (customClasses.exists(name)) - error(EAlreadyExistingClass(name)); + var toSetName:String = setAlias != null ? setAlias : name; + + if (customClasses.exists(toSetName)) + error(EAlreadyExistingClass(toSetName)); inline function importVar(thing:String):String { if (thing == null) @@ -710,7 +713,8 @@ class Interp { final variable:Class = variables.exists(thing) ? cast variables.get(thing) : null; return variable == null ? thing : Type.getClassName(variable); } - customClasses.set(name, new CustomClassHandler(this, name, fields, importVar(extend), [for (i in interfaces) importVar(i)])); + customClasses.set(toSetName, new CustomClassHandler(this, name, fields, importVar(extend), [for (i in interfaces) importVar(i)])); + setAlias = null; case EImport(c, n, isUsing): if (!importEnabled) return null; @@ -770,8 +774,11 @@ class Interp { } if (cl == null && en == null) { - if (importFailedCallback == null || !importFailedCallback(oldSplitName)) + setAlias = n; + if (importFailedCallback == null || !importFailedCallback(oldSplitName)){ + setAlias = null; error(EInvalidClass(oldClassName)); + } } else { if (en != null) { if(isUsing) error(EInvalidClass(oldClassName)); diff --git a/hscript/Tools.hx b/hscript/Tools.hx index e902d2d..9dd47a2 100644 --- a/hscript/Tools.hx +++ b/hscript/Tools.hx @@ -130,4 +130,7 @@ class Tools { #end } + public static inline function isCustomAbstract(obj:Dynamic):Bool + return obj != null && obj is IHScriptAbstractBehaviour; + } \ No newline at end of file