Jump to page: 1 2
Thread overview
modulename
Sep 04, 2012
Ellery Newcomer
Sep 04, 2012
Andrej Mitrovic
Sep 04, 2012
Ellery Newcomer
Sep 04, 2012
Andrej Mitrovic
Sep 05, 2012
captaindet
Sep 06, 2012
captaindet
Sep 05, 2012
Jonathan M Davis
Sep 05, 2012
Andrej Mitrovic
Sep 04, 2012
Jonathan M Davis
Sep 04, 2012
Ellery Newcomer
Sep 04, 2012
Andrej Mitrovic
Sep 04, 2012
Jonathan M Davis
Sep 05, 2012
Jonathan M Davis
Sep 05, 2012
Andrej Mitrovic
September 04, 2012
anybody know a neat trick to get the module name that a function is being called in a la

void foobar(size_t line = __LINE__) {
}

std.traits.moduleName looks like it almost does it, but it needs a symbol from the module.
September 04, 2012
__FILE__?

On 9/4/12, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> anybody know a neat trick to get the module name that a function is being called in a la
>
> void foobar(size_t line = __LINE__) {
> }
>
> std.traits.moduleName looks like it almost does it, but it needs a symbol from the module.
>
September 04, 2012
On 09/04/2012 12:41 PM, Andrej Mitrovic wrote:
> __FILE__?
>

It doesn't necessarily have the exact package hierarchy. e.g:

// wonka.d
module willy.wonka;

pragma(msg, __FILE__);

// end wonka.d


dmd wonka.d

gives

"wonka.d"

but

dmd willy/wonka.d

gives

"willy/wonka.d"
September 04, 2012
 9/4/12, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> On 09/04/2012 12:41 PM, Andrej Mitrovic wrote:
>> __FILE__?
>>
>
> It doesn't necessarily have the exact package hierarchy.

We could really use __MODULE__ then. I think it's been asked before but I didn't see any enhancement request in buzilla.
September 04, 2012
On Tuesday, September 04, 2012 21:41:24 Andrej Mitrovic wrote:
> __FILE__?

That'll mostly work, but it's perfectly possible to give a module a name which is completely different from the file name.

But it looks like we now have std.traits.moduleName, so presumably that will do the trick.

- Jonathan M Davis
September 04, 2012
On 9/4/12, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> But it looks like we now have std.traits.moduleName, so presumably that will do the trick.

How will that do the trick if you don't have the reference to the invoking module?
September 04, 2012
On 09/04/2012 01:16 PM, Jonathan M Davis wrote:
> On Tuesday, September 04, 2012 21:41:24 Andrej Mitrovic wrote:
>> __FILE__?
>
> That'll mostly work, but it's perfectly possible to give a module a name which
> is completely different from the file name.
>
> But it looks like we now have std.traits.moduleName, so presumably that will
> do the trick.
>
> - Jonathan M Davis
>

moduleName needs a symbol
September 04, 2012
On Tuesday, September 04, 2012 22:40:19 Andrej Mitrovic wrote:
> On 9/4/12, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> > But it looks like we now have std.traits.moduleName, so presumably that will do the trick.
> 
> How will that do the trick if you don't have the reference to the invoking module?

Clearly, I didn't read the OP clearly enough.

Unless you can get code to be generated in the calling scope (e.g. with mixins), then the _only_ access that you have to anything in the calling scope is with __FILE__ and __LINE__. And they only work that way because they're treated as special cases (they _don't_ work that way in C/C++). Pretty much by definition, anything that you type is in the scope that you type it.

You _might_ be able to get it to work by having the caller explicitly pass something via an alias template parameter, but if you wanted something explicit, you could have the caller just pass a string with the module's name. I pretty darn sure that there's no way to get the compiler to tell you what you're looking for without the caller doing something.

- Jonathan M Davis
September 04, 2012
On Tue, Sep 4, 2012 at 2:00 PM, Jonathan M Davis <jmdavisProg@gmx.com>wrote:

> On Tuesday, September 04, 2012 22:40:19 Andrej Mitrovic wrote:
> > On 9/4/12, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> > > But it looks like we now have std.traits.moduleName, so presumably that will do the trick.
> >
> > How will that do the trick if you don't have the reference to the invoking module?
>
> Clearly, I didn't read the OP clearly enough.
>
> Unless you can get code to be generated in the calling scope (e.g. with
> mixins), then the _only_ access that you have to anything in the calling
> scope
> is with __FILE__ and __LINE__. And they only work that way because they're
> treated as special cases (they _don't_ work that way in C/C++).


C/C++ may not need __FILE__ and __LINE__ to get evaluated at the call site because C/C++ have preprocessor macros to get around this problem.


September 04, 2012
On Tue, Sep 4, 2012 at 1:36 PM, Andrej Mitrovic <andrej.mitrovich@gmail.com>wrote:

>  9/4/12, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> > On 09/04/2012 12:41 PM, Andrej Mitrovic wrote:
> >> __FILE__?
> >>
> >
> > It doesn't necessarily have the exact package hierarchy.
>
> We could really use __MODULE__ then. I think it's been asked before but I didn't see any enhancement request in buzilla.
>

+1. std.log would love this feature.


« First   ‹ Prev
1 2