www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - All members of a package.d module using string lookup.

reply Ethan <gooberman gmail.com> writes:
I've got some weird juju during a DMD upgrade. The code I've 
posted below is representative of code that used to work for me 
to scrape for objects to bind with Binderoo when using package.d 
to make a folder a module. It has been working for a while. Now 
it doesn't.

And, weirdly, testing on godbolt with every compiler supported 
shows *it never should have worked*.

So. Using nothing but a module name as a string, what's the 
correct way to get all members when that module is a package.d 
implementation?

-----

https://run.dlang.io/is/VOWVoT

-----

template Alias( alias A )
{
	alias Alias = A;
}

template ModuleFromName( string strModuleName )
{
	mixin( "import " ~ strModuleName ~ "; alias ModuleFromName = 
Alias!( " ~ strModuleName ~ " );" );
}

alias StdRegex = ModuleFromName!"std.regex";

pragma( msg, StdRegex.stringof );
pragma( msg, "std.regex members: " ~ __traits( allMembers, 
StdRegex ).stringof );
Aug 26 2020
parent Nils Lankila <NilsLankila gmx.us> writes:
On Wednesday, 26 August 2020 at 22:25:18 UTC, Ethan wrote:
 I've got some weird juju during a DMD upgrade. The code I've 
 posted below is representative of code that used to work for me 
 to scrape for objects to bind with Binderoo when using 
 package.d to make a folder a module. It has been working for a 
 while. Now it doesn't.

 And, weirdly, testing on godbolt with every compiler supported 
 shows *it never should have worked*.

 So. Using nothing but a module name as a string, what's the 
 correct way to get all members when that module is a package.d 
 implementation?
For now this is not possible because there was a bug with packages and `__traits(allMembers)`. You're lucky because it's been fixed two days ago, see [1], but that still has to find its path to the stable branch. By the way if Bindero relies on `__traits(allMembers)` on whole modules, I advice you to test this PR, as it may break you code. [1] https://github.com/dlang/dmd/pull/11619 [2] https://github.com/dlang/dmd/pull/11627
Aug 26 2020