What variables (like @type) are available in macros?

Hi, I read about @type in macros in the docs, and found @def in the code, but are there any other variables available?

I’m preparing a pull request to update the docs, if there are any others that should be added it would be nice to know about them.


That’s great, thanks for picking this up :heart_hands:

There’s also @top_level which refers to the Program i.e. the top level scope.
All macro meta vars are defined in a single place in the macro interpreter:

There’s an additional var, @caller coming in (Expose macro `Call` context via new `@caller` macro ivar by Blacksmoke16 · Pull Request #14048 · crystal-lang/crystal · GitHub) and it already has a docs PR: Document new `@caller` macro ivar by Blacksmoke16 · Pull Request #724 · crystal-lang/crystal-book · GitHub
You might want to start working on top of that (not required, but could be easier in order to incorporate everything).

1 Like

And please note that the semantics of @type are a bit… wanky. This may need refinement.

Well, it seems to magically have resolved itself :slight_smile: