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
Introduce KALEIDOSCOPE_API_VERSION #270
Conversation
As we guarantee backwards compatibility throughout a major version, it helps if we have that version available, so plugins / sketches can check if they are compatible, and issue a helpful error if they are not. As further convenience, defining `KALEIDOSCOPE_REQUIRED_API_VERSION` before including `Kaleidoscope.h` will result in a check being done by Kaleidoscope, and an error printed if it does not match the API shipped. Signed-off-by: Gergely Nagy <algernon@keyboard.io>
Intended usage: #define KALEIDOSCOPE_REQUIRED_API_VERSION 2
#include "Kaleidoscope.h" or #include "Kaleidoscope.h"
#if KALEIDOSCOPE_API_VERSION != 1
#error This plugin requires Kaleidoscope version 1.x!
#endif or #include "Kaleidoscope.h"
// ... somewhere in the code ...
#if KALEIDOSCOPE_API_VERSION == 1
// do something supported by Kaleidoscope v1.x
#elif KALEIDOSCOPE_API_VERSION == 2
// do something supported by Kaleidoscope v2.x
#else
#error Unsupported Kaleidoscope version. Only v1.x and 2.x are supported.
#endif |
Would it be possible for the API mismatch error message to also state what the required and observed version numbers are? I think that would add to the helpfulness of the error message. I will also note that since the check enforces that the required API version and provided API version exactly match, any bump of the API version number in Kaleidoscope automatically breaks all plugins. Plugins have no way to depend on, say, API version >= 2. This is probably the desired behavior - during an API version bump, all plugins have to manually inspect themselves and mark themselves compatible with the new version after making any required changes. Is it possible for plugins to mark themselves compatible with more than one version? E.g., in @algernon's third example in his comment above, I suppose that plugin could just not define |
It would be super helpful, yes, but we can't. When using
Yes it is. The assumption is that most plugins will support only a single version, and the ones that support more, are an exception. For those, as you write too, the solution is to not use |
What about defining check function macros that operate on #define KALEIDOSCOPE_REQUIRE_API_VERSION_GREATER(N) \
static_assert(KALEIDOSCOPE_API_VERSION > N, "...")
|
I do not want to introduce any other macro than a strict equality check, but the |
Yeah. Right. Shouldn't post after so much red wine. The 'greater' is nonsense. The |
The results look neat, thanks @noseglasses!
|
Use `static_assert` instead of `#error` to report an API mismatch, resulting in a much more informative error message. Thanks to @cdisselkoen for the request, and @noseglasses for the `static_assert` idea! Signed-off-by: Gergely Nagy <algernon@keyboard.io>
As we guarantee backwards compatibility throughout a major version, it helps if we have that version available, so plugins / sketches can check if they are compatible, and issue a helpful error if they are not. As further convenience, defining
KALEIDOSCOPE_REQUIRED_API_VERSION
before includingKaleidoscope.h
will result in a check being done by Kaleidoscope, and an error printed if it does not match the API shipped.