Documentation + custom classes import alias
This commit is contained in:
@@ -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...
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package hscript;
|
||||
|
||||
/**
|
||||
* Same Interface as IHScriptCustomBehaviour but for Property.
|
||||
*/
|
||||
interface IHScriptCustomAccessBehaviour extends IHScriptCustomBehaviour {
|
||||
var __allowSetGet:Bool;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<String>;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package hscript;
|
||||
|
||||
/**
|
||||
* Special Interface for handling new instances of an object.
|
||||
*/
|
||||
interface IHScriptCustomConstructor {
|
||||
public function hnew(args:Array<Dynamic>):Dynamic;
|
||||
}
|
||||
+11
-4
@@ -138,6 +138,7 @@ class Interp {
|
||||
var returnValue:Dynamic;
|
||||
|
||||
var isBypassAccessor:Bool = false;
|
||||
var setAlias:Null<String> = 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<Any> = 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));
|
||||
|
||||
@@ -130,4 +130,7 @@ class Tools {
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function isCustomAbstract(obj:Dynamic):Bool
|
||||
return obj != null && obj is IHScriptAbstractBehaviour;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user