Hi there,
using macros we have access to the special variables __modules__
which gives me the current module, and __source__
which gives linenumber and file.
Neither of them can tell me in which subfunction the code is executed.
Lets do a pseudo example
module A
macro currentnestedlevel()
# TODO how to do this?
end
function f()
function g()
@currentnestedlevel
end
g()
end
end
A.f() # 'A.f.g' or similar
We could fake this with a module-level macro which parses this information and puts it into the macro as an extra argument. However this only works with named functions and fails for anonymous ones as we cannot see their unique identifier from the source code alone.
Why I need this: From time to time I want to store and access a state for my macro call, so that the second call can be different than the first one, depending on the state. Storing is easy, however accessing seems impossible in local scope, so I have to store the information at module level and hence cannot distinguish between macros in nested levels.