5 ms·
I don't understand the example. Does it even compile? It's been a long time since I've used C, so maybe it's using some syntax that I'm unaware of? IE: What d
by gwbas1c 1y ago
I don't understand the example. Does it even compile?
It's been a long time since I've used C, so maybe it's using some syntax that I'm unaware of?
IE: What defines "home" that is referenced as an argument to the "appRoute" function, and then passed to the "get" function to set up the "/home" route? Is "home" defined in lavandula.h, or is this really pseudocode?
- deleted 1y ago[deleted]
- diath 1y agoIt's a macro: #define appRoute(name) HttpResponse name(AppContext ctx)
- ashtonjamesd 1y agoHi, sorry maybe I should've added a comment for that. The 'appRoute' is a macro that expands to a function signature. The macro is: '#define appRoute(name) HttpResponse name(AppContext ctx)' and the parameter I passed as 'home' is expanded into the function name. The reason is because all controller function signatures are the same, so just writing 'appRoute' allows the developer to save time writing endpoints! It is a tradeoff between readability and development speed. And one of the ideas behind the framework is succint and minimal code.
- gwbas1c 1y agoSo it creates a function called "home", and that is what you pass to get? Makes sense, thanks!
- nodesocket 1y agoThanks for explaining. I was also a bit confused at a first where the home variable being passed into get() was coming from.
- hofrogs 1y ago"appRoute(home)" is a macro that expands to a function called "home": #define appRoute(name) HttpResponse name(AppContext ctx)
- rnhmjoj 1y agoIf I can guess, I would say `appRoute` is a macro that defines a struct called `home` with that handler being assigned to some field as a function pointer.
- deleted 1y ago[deleted]