digitalmars.D.learn - Using __traits to find functions in sub-modules
- nrgyzer (51/51) Oct 16 2014 Hi,
- ketmar via Digitalmars-d-learn (5/7) Oct 16 2014 On Thu, 16 Oct 2014 18:39:48 +0000
- John Colvin (5/56) Oct 16 2014 perhaps you could get somewhere by using a package.d in every
- nrgyzer (3/70) Oct 17 2014 Hm, importing the package doesn't help :(
Hi, I'm using structs to describe my functions: struct example { string name; uint someValue; } module mod.example1; example("example1", 1) void myFunction() { // do something } module mod.example2; example("example2", 2) void myFunction() { // do something } I'm using the struct to describe functions in different modules. Now, I want add all functions which are described using the example-struct to an array during compile time. But how can I do this? I know, I can use __trait(allMembers, mod.example1) and __trait(allMembers, mod.example2), but I only want specify the parent module (mod), for instance: void main() { foreach (member, __traits(allMembers, mod)) { writeln(member); } } But this only shows "object" - nothing else. No sub-modules like mod.example1 or mod.example2. So, how can I find all functions that are described using my structure during compile time and add them to an array? I already tried this: void main() { foreach (cmodule; ModuleInfo) { foreach (submodule; __traits(allMembers, cmodule)) { // ... also tried: foreach (submodule; __traits(allMembers, mixin(cmodule.name))), cmodule.name is not available during compile time... } } } But it always stats that 'cmodule' has no members. Does anyone know how to solve the problem?
Oct 16 2014
On Thu, 16 Oct 2014 18:39:48 +0000 nrgyzer via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:But it always stats that 'cmodule' has no members. Does anyone=20 know how to solve the problem?there is no non-hackish solution, afaik. there is no even hackish, but reliable one.
Oct 16 2014
On Thursday, 16 October 2014 at 18:39:50 UTC, nrgyzer wrote:Hi, I'm using structs to describe my functions: struct example { string name; uint someValue; } module mod.example1; example("example1", 1) void myFunction() { // do something } module mod.example2; example("example2", 2) void myFunction() { // do something } I'm using the struct to describe functions in different modules. Now, I want add all functions which are described using the example-struct to an array during compile time. But how can I do this? I know, I can use __trait(allMembers, mod.example1) and __trait(allMembers, mod.example2), but I only want specify the parent module (mod), for instance: void main() { foreach (member, __traits(allMembers, mod)) { writeln(member); } } But this only shows "object" - nothing else. No sub-modules like mod.example1 or mod.example2. So, how can I find all functions that are described using my structure during compile time and add them to an array? I already tried this: void main() { foreach (cmodule; ModuleInfo) { foreach (submodule; __traits(allMembers, cmodule)) { // ... also tried: foreach (submodule; __traits(allMembers, mixin(cmodule.name))), cmodule.name is not available during compile time... } } } But it always stats that 'cmodule' has no members. Does anyone know how to solve the problem?perhaps you could get somewhere by using a package.d in every package? If it needs to work on packages you don't control then I don't really know :/
Oct 16 2014
On Thursday, 16 October 2014 at 19:19:21 UTC, John Colvin wrote:On Thursday, 16 October 2014 at 18:39:50 UTC, nrgyzer wrote:Hm, importing the package doesn't help :( Okay, I see... I've to solve the problem using another idea...Hi, I'm using structs to describe my functions: struct example { string name; uint someValue; } module mod.example1; example("example1", 1) void myFunction() { // do something } module mod.example2; example("example2", 2) void myFunction() { // do something } I'm using the struct to describe functions in different modules. Now, I want add all functions which are described using the example-struct to an array during compile time. But how can I do this? I know, I can use __trait(allMembers, mod.example1) and __trait(allMembers, mod.example2), but I only want specify the parent module (mod), for instance: void main() { foreach (member, __traits(allMembers, mod)) { writeln(member); } } But this only shows "object" - nothing else. No sub-modules like mod.example1 or mod.example2. So, how can I find all functions that are described using my structure during compile time and add them to an array? I already tried this: void main() { foreach (cmodule; ModuleInfo) { foreach (submodule; __traits(allMembers, cmodule)) { // ... also tried: foreach (submodule; __traits(allMembers, mixin(cmodule.name))), cmodule.name is not available during compile time... } } } But it always stats that 'cmodule' has no members. Does anyone know how to solve the problem?perhaps you could get somewhere by using a package.d in every package? If it needs to work on packages you don't control then I don't really know :/
Oct 17 2014