|
@@ -23,121 +23,12 @@
|
|
|
* DAMAGE.
|
|
|
*/
|
|
|
|
|
|
-/**
|
|
|
- The different kind of basic types.
|
|
|
-**/
|
|
|
-enum BasicType {
|
|
|
- TNull;
|
|
|
- TInt;
|
|
|
- TFloat;
|
|
|
- TBool;
|
|
|
- TObject;
|
|
|
- TEnum;
|
|
|
- TFunction;
|
|
|
- TUnknown;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- A class contains meta data about the class instance and an access to the prototype.
|
|
|
-**/
|
|
|
-typedef Class = {
|
|
|
-
|
|
|
- /**
|
|
|
- The complete class name
|
|
|
- **/
|
|
|
- var __name__ : Array<String>;
|
|
|
-
|
|
|
- /**
|
|
|
- The Class constructor, or [null] if the class does not have one
|
|
|
- **/
|
|
|
- var __construct__ : Dynamic;
|
|
|
-
|
|
|
- /**
|
|
|
- The superclass which the class extends, or [null] if the class does not extend any class
|
|
|
- **/
|
|
|
- var __super__ : Class;
|
|
|
-
|
|
|
- /**
|
|
|
- The list of interfaces implemented by this class.
|
|
|
- **/
|
|
|
- var __interfaces__ : Array<Class>;
|
|
|
-
|
|
|
- /**
|
|
|
- The class prototype, containing all class fields
|
|
|
- **/
|
|
|
- var prototype : Dynamic;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
The Reflect API is a way to manipulate values dynamicly through an
|
|
|
abstract interface in an untyped manner. Use with care.
|
|
|
**/
|
|
|
class Reflect {
|
|
|
|
|
|
- /**
|
|
|
- Returns the basic type of any value.
|
|
|
- **/
|
|
|
- public static function typeof( v : Dynamic ) : BasicType {
|
|
|
- untyped {
|
|
|
- #if flash
|
|
|
- var t = __typeof__(v);
|
|
|
- if( t == "number" ) {
|
|
|
- if( Math.ceil(v) == v && isFinite(v) )
|
|
|
- return TInt;
|
|
|
- return TFloat;
|
|
|
- }
|
|
|
- if( v == true || v == false )
|
|
|
- return TBool;
|
|
|
- if( v == null )
|
|
|
- return TNull;
|
|
|
- if( t == "function" ) {
|
|
|
- if( v.__interfaces__ == null )
|
|
|
- return TFunction;
|
|
|
- return TObject;
|
|
|
- }
|
|
|
- if( t == "object" || t == "string" ) {
|
|
|
- if( v.__enum__ != null )
|
|
|
- return TEnum;
|
|
|
- return TObject;
|
|
|
- }
|
|
|
- return TUnknown;
|
|
|
- #else neko
|
|
|
- return switch( __dollar__typeof(v) ) {
|
|
|
- case __dollar__tint: TInt;
|
|
|
- case __dollar__tfloat: TFloat;
|
|
|
- case __dollar__tbool: TBool;
|
|
|
- case __dollar__tfunction: TFunction;
|
|
|
- case __dollar__tobject: if( v.__enum__ == null ) TObject else TEnum;
|
|
|
- case __dollar__tnull: TNull;
|
|
|
- default: TUnknown;
|
|
|
- }
|
|
|
- #else js
|
|
|
- var t = __js__("typeof")(v);
|
|
|
- if( t == "number" ) {
|
|
|
- if( Math.ceil(v) == v && isFinite(v) )
|
|
|
- return TInt;
|
|
|
- return TFloat;
|
|
|
- }
|
|
|
- if( v == true || v == false )
|
|
|
- return TBool;
|
|
|
- if( v == null )
|
|
|
- return TNull;
|
|
|
- if( t == "function" ) {
|
|
|
- if( v.__interfaces__ == null )
|
|
|
- return TFunction;
|
|
|
- return TObject;
|
|
|
- }
|
|
|
- if( t == "object" || t == "string" ) {
|
|
|
- if( v.__enum__ != null )
|
|
|
- return TEnum;
|
|
|
- return TObject;
|
|
|
- }
|
|
|
- return TUnknown;
|
|
|
- #else error
|
|
|
- #end
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
Creates an empty object.
|
|
|
**/
|
|
@@ -316,93 +207,6 @@ class Reflect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- Returns the class of an object
|
|
|
- **/
|
|
|
- public static function getClass( o : Dynamic ) : Class {
|
|
|
- return untyped
|
|
|
- #if flash
|
|
|
- o.__class__;
|
|
|
- #else js
|
|
|
- if( o == null )
|
|
|
- null;
|
|
|
- else
|
|
|
- o.__class__;
|
|
|
- #else neko
|
|
|
- if( __dollar__typeof(o) != __dollar__tobject )
|
|
|
- null;
|
|
|
- else
|
|
|
- o.__class__;
|
|
|
- #else error
|
|
|
- #end
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- Evaluates a class from a name
|
|
|
- **/
|
|
|
- public static function resolveClass( name : Array<String> ) : Class {
|
|
|
- var cl : Class;
|
|
|
- untyped {
|
|
|
- #if flash
|
|
|
- cl = __eval__(name.join("."));
|
|
|
- #else js
|
|
|
- cl = eval(name.join("."));
|
|
|
- #else neko
|
|
|
- cl = untyped field(neko.Boot.__classes,name[0]);
|
|
|
- var i = 1;
|
|
|
- while( cl != null && i < name.length ) {
|
|
|
- cl = field(cl,name[i]);
|
|
|
- i += 1;
|
|
|
- }
|
|
|
- #else error
|
|
|
- #end
|
|
|
- }
|
|
|
- if( cl == null || cl.__interfaces__ == null )
|
|
|
- return null;
|
|
|
- return cl;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- Evaluates an enum from a name
|
|
|
- **/
|
|
|
- public static function resolveEnum( name : Array<String> ) : Dynamic {
|
|
|
- var e : Dynamic;
|
|
|
- untyped {
|
|
|
- #if flash
|
|
|
- e = __eval__(name.join("."));
|
|
|
- #else js
|
|
|
- e = eval(name.join("."));
|
|
|
- #else neko
|
|
|
- e = untyped field(neko.Boot.__classes,name[0]);
|
|
|
- var i = 1;
|
|
|
- while( e != null && i < name.length ) {
|
|
|
- e = field(cl,name[i]);
|
|
|
- i += 1;
|
|
|
- }
|
|
|
- #else error
|
|
|
- #end
|
|
|
- }
|
|
|
- if( e == null || e.__ename__ == null )
|
|
|
- return null;
|
|
|
- return e;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- Change the class prototype of an object
|
|
|
- **/
|
|
|
- public static function setPrototype( obj : Dynamic, proto : Dynamic ) {
|
|
|
- #if flash
|
|
|
- obj.__proto__ = proto;
|
|
|
- #else js
|
|
|
- obj.__proto__ = proto;
|
|
|
- #else neko
|
|
|
- untyped __dollar__objsetproto(obj,proto);
|
|
|
- #else error
|
|
|
- #end
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
Tells if a value is a function or not.
|
|
|
**/
|