1 2 module witchcraft.impl.modules; 3 4 import witchcraft; 5 6 import std.traits; 7 8 class ModuleImpl(alias M) : Module 9 { 10 mixin WitchcraftField; 11 mixin WitchcraftMethod; 12 13 this() 14 { 15 foreach(name; __traits(derivedMembers, M)) 16 { 17 // HACK: There's no good way to determine if something is a field. 18 static if(is(typeof(__traits(getMember, M, name))) && 19 !is(typeof(__traits(getMember, M, name)) == class) && 20 !is(typeof(__traits(getMember, M, name)) == enum) && 21 !is(typeof(__traits(getMember, M, name)) == function) && 22 !is(typeof(__traits(getMember, M, name)) == struct) && 23 !is(typeof(__traits(getMember, M, name)) == void) && 24 !is(typeof(__traits(getMember, M, name)) == union)) 25 { 26 _fields[name] = new FieldMixin!(M, name); 27 } 28 } 29 30 foreach(name; __traits(derivedMembers, M)) 31 { 32 static if(is(typeof(__traits(getMember, M, name)) == function)) 33 { 34 // HACK: For some reason, object.isnan causes a linking error on Windows. 35 static if(fullyQualifiedName!(__traits(getMember, M, name)) != "object.isnan") 36 { 37 foreach(index, overload; __traits(getOverloads, M, name)) 38 { 39 _methods[name] ~= new MethodMixin!(M, name, index); 40 } 41 } 42 } 43 } 44 } 45 46 string getFullName() const 47 { 48 return fullyQualifiedName!M; 49 } 50 51 string getName() const 52 { 53 return M.stringof; 54 } 55 56 string getProtection() const 57 { 58 return __traits(getProtection, M); 59 } 60 61 @property 62 final bool isAccessible() const 63 { 64 return true; 65 } 66 }