Module name compile time constant?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Apr 25 06:40:51 PDT 2008


davidl wrote:
> 在 Tue, 15 Apr 2008 13:00:57 +0800,Bill Baxter 
> <dnewsgroup at billbaxter.com> 写道:
> 
>> Walter Bright wrote:
>>> davidl wrote:
>>>>
>>>> module abc.super.long.pack.awesome.mod;
>>>>
>>>> what if i need the string of "abc.super.long.pack.awesome.mod" 
>>>> generally and don't want to copy paste differently in all my modules?
>>>  alias abc.super.long.pack.awesome.mod foo;
>>
>> I think he wants that full module name as a char[], though.
>>
>> Is that what you want, Davidl?
>>
>> Or do you just want to be able to say
>>
>>
>>     import short.awesome; // aka "import abc.super.long.pack.awesome.mod"
>>
>> If that's what you want you can create a module in short/awesome.d 
>> that contains just:
>>
>>    module short.awesome;
>>    public import abc.super.long.pack.awesome.mod;
>>
>> But somehow I'm thinking you actually want to automatically get that 
>> module name as a string.
>>
>> How about going the other way around?  Start with a string?
>>
>> string foo = "abc.super.long.pack.awesome.mod";
>> mixin(import_module(foo));
>>
>> where import_module  is
>>
>> string import_module(string name) {
>>     return "import " ~ name ";" ;
>> }
>>
>> If those don't answer your question you're gonna have to be more 
>> specific.
>>
>>
>> --bb
> 
> Yes, i want the string. But I don't want to modify the module part to 
> manually defined strings
> I want some magic of module.name to get the current module name in 
> compile time string form.
> 

I tried this to see if it would work:

---  ---
module foo.test;

void main()
{
	writefln(.stringof);
}


Almost worked! It prints "module test". It would do what you wanted if 
'.stringof' returned the fully qualified module (and didn't have the 
"module " prefix).



-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list