Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Better code commenting of macro magic #103

Closed
VisenDev opened this issue Dec 24, 2024 · 4 comments
Closed

[Documentation] Better code commenting of macro magic #103

VisenDev opened this issue Dec 24, 2024 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@VisenDev
Copy link

I'm having a difficult time figuring out what exactly these lines are supposed to do, and I'd imagine i'm not the only one. Given that the CLAY macro is crucial to build anything with this library, it would be helpful having some more explanations of what these macros actually do. I've read thru them a few times and I'm still a bit lost.

clay/clay.h

Lines 95 to 113 in 6a9b723

#define CLAY__ELEMENT_INTERNAL(...) \
for (\
CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(), __VA_ARGS__, Clay__ElementPostConfiguration(), 0); \
CLAY__ELEMENT_DEFINITION_LATCH < 1; \
++CLAY__ELEMENT_DEFINITION_LATCH, Clay__CloseElement() \
)
#define CLAY__6_ARGS(a, b, c, d, e, f) a, b, c, d, e, f
#define CLAY__5_ARGS(a, b, c, d, e) a, b, c, d, e
#define CLAY__4_ARGS(a, b, c, d) a, b, c, d
#define CLAY__3_ARGS(a, b, c) a, b, c
#define CLAY__2_ARGS(a, b) a, b
#define CLAY__1_ARGS(a) a
#define CLAY__0_ARGS() Clay__Noop()
#define CLAY__ARGS_OVERRIDE(_0, _1, _2, _3, _4, _5, _6, NAME, ...) NAME
// Publicly visible layout element macros -----------------------------------------------------
#define CLAY(...) CLAY__ELEMENT_INTERNAL(CLAY__ARGS_OVERRIDE("empty", ##__VA_ARGS__, CLAY__6_ARGS, CLAY__5_ARGS, CLAY__4_ARGS, CLAY__3_ARGS, CLAY__2_ARGS, CLAY__1_ARGS, CLAY__0_ARGS)(__VA_ARGS__))

@nicbarker
Copy link
Owner

Hello 👋
Agree, there is some real trickery going on here that I had a lot of help with, so it would be great for us to document it with a big block comment.

@nicbarker nicbarker added the documentation Improvements or additions to documentation label Dec 24, 2024
@nicbarker nicbarker self-assigned this Dec 24, 2024
@nicbarker
Copy link
Owner

Courtesy of some great work from @FintasticMan #119

image

@nicbarker
Copy link
Owner

Explanation of the remaining (much smaller) CLAY macro has been added in this commit: a44423a

@VisenDev
Copy link
Author

VisenDev commented Jan 2, 2025

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants