can your 'inspect' method handle:
* multiple arguments?
* expressions?
I wrote a function that does both, it's one of those things that are very useful for quick debugging:
import util.prettyprint;
void main(){
int x=23;
double y=2.4;
writelnL(x,y,x*y);
}
//output:
file test.d:7 {
x=int{23},
y=double{2.4},
x*y=double{55.2},
}
-----
The way it works:
void writelnL(string file=__FILE__, Line_t line=__LINE__, T...)(T args){
...
auto argNames=getArgNamesFromFile(file,line);
...
}
This reads at runtime file/line and caches the information with memoize to avoid re-reading the same file/line multiple times. I had also tried reading the file/line at compile time using import(file)[line] but that resulted in massive compile time slow-downs even when the actual writelnL wasn't used at runtime. Then the code parses the line to extract each argument names using a simplified D grammar.
However this still has some runtime penalty (reading a whole file just for 1 line) and is doing more work than necessary, as compiler has access to this info.
I've already asked for this in the past (see email: "feature request: __ARGS__ for logging (cf __FILE__, __LINE__, __FUNC___):
but Jacob pointed out that AST macros would make this un-necessary (like wise with another proposal I made "proposal: a new string litteral to embed variables in a string" ):
"I don't think that __ARGS__ is a bad idea, I just think that there are several features in D which could be replaced with a library solution using AST macros (if those were available)"
So let's either get a roadmap for introducing AST macros (preferred) or let's allow this very simple __ARGS__ in the language.