Scripted Enums WIP
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package hscript;
|
||||
|
||||
import hscript.utils.UnsafeReflect;
|
||||
|
||||
// TODO: scripted enums
|
||||
@:structInit
|
||||
class HEnum implements IHScriptCustomBehaviour{
|
||||
private var enumValues(default, null) = {};
|
||||
|
||||
public function setEnum(name:String, enumValue:Dynamic):Void {
|
||||
UnsafeReflect.setField(enumValues, name, enumValue);
|
||||
}
|
||||
|
||||
public function getEnum(name:String):Null<Dynamic> {
|
||||
if(Reflect.hasField(enumValues, name)) return Reflect.field(enumValues, name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hget(name:String):Dynamic {
|
||||
return getEnum(name);
|
||||
}
|
||||
|
||||
public function hset(name:String, val:Dynamic):Dynamic {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -740,10 +740,11 @@ class Interp {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(isUsing && customClasses.exists(toSetName)) {
|
||||
// NOTE: you will need to create the class first before
|
||||
if(customClasses.exists(toSetName)) { // custom class is already parsed and imported
|
||||
// NOTE: you will need to create/import
|
||||
// the custom class first before
|
||||
// setting the extension
|
||||
if(!usingHandler.entryExists(toSetName))
|
||||
if(isUsing && !usingHandler.entryExists(toSetName))
|
||||
setCustomClassUsing(toSetName, customClasses.get(toSetName));
|
||||
return null;
|
||||
}
|
||||
@@ -793,13 +794,15 @@ class Interp {
|
||||
if (en != null) {
|
||||
if(isUsing) error(EInvalidClass(oldClassName));
|
||||
// ENUM!!!!
|
||||
var enumThingy = {};
|
||||
var enumThingy:HEnum = {};
|
||||
for (c in en.getConstructors()) {
|
||||
try {
|
||||
UnsafeReflect.setField(enumThingy, c, en.createByName(c));
|
||||
//UnsafeReflect.setField(enumThingy, c, en.createByName(c));
|
||||
enumThingy.setEnum(c, en.createByName(c));
|
||||
} catch(e) {
|
||||
try {
|
||||
UnsafeReflect.setField(enumThingy, c, UnsafeReflect.field(en, c));
|
||||
//UnsafeReflect.setField(enumThingy, c, UnsafeReflect.field(en, c));
|
||||
enumThingy.setEnum(c, UnsafeReflect.field(en, c));
|
||||
} catch(ex) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user