Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
// ++
module test;
import std;
class myClass{ void foo(){}}
void myFunction1(){}
void main()
{
// list the first user defined member of this module (other
than main)
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote:
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
https://dlang.org/spec/traits.html#getLocation
That?
On Saturday, 13 November 2021 at 06:05:37 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote:
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
https://dlang.org/spec/traits.html#getLocation
That?
Thanks. That
On 11/12/21 11:00 PM, forkit wrote:
> // nope. writes the line no. of the foreach loop
mixin(m) seems to solve the issue, which I think necessitates 'static if':
static foreach(m; __traits(allMembers, mixin(__MODULE__)))
{
static if(m == "std" || m == "object" || m == "main")
On Saturday, 13 November 2021 at 07:20:14 UTC, Ali Çehreli wrote:
It works because we mix-in the value of the string 'm', which
becomes a symbol.
('foreach' instead of 'static foreach' works as well.)
Ali
Thanks. Really appreciate the help provided in this thread :-)
Final working code be
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote:
int i;
foreach(m; __traits(allMembers, mixin(__MODULE__)))
// ...
__traits(getLocation, mixin(m))[1]);
What you really should be doing is this:
```d
static import mod = mixin(__MODULE__);
foreach (i, name; __traits(a
On Saturday, 13 November 2021 at 17:22:16 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote:
int i;
foreach(m; __traits(allMembers, mixin(__MODULE__)))
// ...
__traits(getLocation, mixin(m))[1]);
What you really should be doing is this:
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote:
However, there is no isClass method. Why not?
How do I determine if a member is a class.. I wonder...
```
static if (is(something == class)) { /* ... */ }
```
or, if member is an instance
```
static if (is(typeof(something) == class
On Sunday, 14 November 2021 at 04:24:09 UTC, Stanislav Blinov
wrote:
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote:
However, there is no isClass method. Why not?
How do I determine if a member is a class.. I wonder...
```
static if (is(something == class)) { /* ... */ }
```
or,
On 11/13/21 8:05 PM, forkit wrote:
> static import mod = mixin(__MODULE__);
>
> That statement above would not compile.
I don't understand myself but all of it as a single string works:
mixin("static import mod = " ~ __MODULE__ ~ ";");
Ali
10 matches
Mail list logo