A bit if documentation + cleanup
This commit is contained in:
+7
-14
@@ -31,7 +31,6 @@ class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
var __class:CustomClassHandler;
|
||||
var __superClass:IHScriptCustomClassBehaviour;
|
||||
var __constructor:Function;
|
||||
var fields:Array<Expr>;
|
||||
|
||||
public function new(__class:CustomClassHandler, ?args:Array<Dynamic>) {
|
||||
this.__class = __class;
|
||||
@@ -44,14 +43,11 @@ class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
__interp.publicVariables = __class.ogInterp.publicVariables;
|
||||
__interp.staticVariables = __class.ogInterp.staticVariables;
|
||||
|
||||
this.fields = __class.fields;
|
||||
for (f in fields) {
|
||||
for (f in __class.fields) {
|
||||
switch (Tools.expr(f)) {
|
||||
case EVar(n):
|
||||
__class__fields.push(n);
|
||||
case EFunction(_, _, n):
|
||||
__class__fields.push(n);
|
||||
default:
|
||||
case EVar(n): __class__fields.push(n);
|
||||
case EFunction(_, _, n): __class__fields.push(n);
|
||||
default: continue;
|
||||
}
|
||||
@:privateAccess __interp.exprReturn(f);
|
||||
}
|
||||
@@ -154,10 +150,8 @@ 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))
|
||||
return getField(name);
|
||||
@@ -185,9 +179,8 @@ class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
}
|
||||
|
||||
public function hset(name:String, val:Dynamic):Dynamic {
|
||||
if (hasField(name)) {
|
||||
if (hasField(name))
|
||||
return setField(name, val);
|
||||
}
|
||||
|
||||
if (hasStaticField(name)) {
|
||||
__interp.error(ECustom('The field ${name} should be accessed in a static way.'));
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
package hscript;
|
||||
|
||||
import hscript.Interp.DeclaredVar;
|
||||
import hscript.utils.UnsafeReflect;
|
||||
using StringTools;
|
||||
|
||||
// BIG TODO: revamp this
|
||||
/**
|
||||
* Provides handlers for static custom class fields and instantiation.
|
||||
*/
|
||||
@:access(hscript.Property)
|
||||
class CustomClassHandler implements IHScriptCustomConstructor implements IHScriptCustomAccessBehaviour{
|
||||
public static var staticHandler = new StaticHandler();
|
||||
|
||||
public var __allowSetGet:Bool = true;
|
||||
|
||||
public var ogInterp:Interp;
|
||||
public var name:String;
|
||||
public var fields:Array<Expr>;
|
||||
@@ -25,6 +16,8 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
|
||||
private var staticInterp:Interp;
|
||||
private var staticFields:Array<String> = [];
|
||||
|
||||
public var __allowSetGet:Bool = true;
|
||||
|
||||
public function new(ogInterp:Interp, name:String, fields:Array<Expr>, ?extend:String, ?interfaces:Array<String>) {
|
||||
this.ogInterp = ogInterp;
|
||||
this.name = name;
|
||||
@@ -346,7 +339,3 @@ class TemplateClass implements IHScriptCustomBehaviour implements IHScriptCustom
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
final class StaticHandler {
|
||||
public function new() {}
|
||||
}
|
||||
@@ -4,6 +4,27 @@ import hscript.utils.UnsafeReflect;
|
||||
import hscript.Interp;
|
||||
import hscript.Expr.FieldPropertyAccess;
|
||||
|
||||
/**
|
||||
* Special variable that handles 'getter/setter' function calls
|
||||
* depending of the read/write access combination.
|
||||
*
|
||||
* Example:
|
||||
* ```haxe
|
||||
* public var myvar(get, set):Int;
|
||||
* var _myvar:Int = 10;
|
||||
*
|
||||
* function get_myvar():Int {
|
||||
* return _myvar;
|
||||
* }
|
||||
*
|
||||
* function set_myvar(val:Int):Int {
|
||||
* if(val > 10) return _myvar = val;
|
||||
* return val;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see https://haxe.org/manual/class-field-property.html
|
||||
*/
|
||||
@:access(hscript.Interp)
|
||||
@:structInit
|
||||
class Property {
|
||||
|
||||
@@ -14,6 +14,7 @@ import Sys;
|
||||
|
||||
using StringTools;
|
||||
|
||||
// BIG TODO: make typed classes scriptable
|
||||
class ClassExtendMacro {
|
||||
public static inline final FUNC_PREFIX = "_HX_SUPER__";
|
||||
public static inline final CLASS_SUFFIX = "_HSX";
|
||||
|
||||
Reference in New Issue
Block a user