so, I’m currently having a state struct, suffyce it to say I have 5 functions, and I’ll likely have states, so I thought since zig has comptime, is there a way to use comptime to create a function like this, for any struct that has them all?
pub fn State(self: *Menu) state {
return .{
.ptr = self,
.onEnterFn = onEnter,
.onExitFn = onExit,
.onFocusFn = onFocus,
.onUnFocusFn = onUnFocus,
.onEscapeFn = onEscape,
.onUpdateFn = onUpdate,
};
}
like ok, don’t judge lol, I know it’s sorta small, but I’m likely going to use a similar arcotype a lot so I’m wondering if I could shorten it a little? It just feels like one of these days I’m going to accidentally mix up one of them in the wrong place and not notice it until it’s too late so having the compiler deal with it for me is going to be great.
a bit of an off-topic question but I noticed it. Why does zigg know what I mean when I say onEnter and not self.onEnter? I thought when I saw an example of it that it’s a typo but I was surprised that it worked.
also, didn’t put the entire code because probably most people could easily guess what I’m trying to do since it’s used/discussed everywhere so decided just to explain what type of function I’m trying to automate the creation of.