Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active July 3, 2020 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfillion/350356a62c61a1a2640024f8dc6c6770 to your computer and use it in GitHub Desktop.
Save cfillion/350356a62c61a1a2640024f8dc6c6770 to your computer and use it in GitHub Desktop.
Loader for the REAPER C++ API
// Usage:
// if(rec->caller_version != REAPER_PLUGIN_VERSION || !loadAPI(rec->GetFunc))
// return 0;
// See also (bare-bone REAPER extension):
// https://gist.github.com/cfillion/f32b04e75e84e03cc463abb1eda41400
#define REQUIRED_API(name) {(void **)&name, #name, true}
#define OPTIONAL_API(name) {(void **)&name, #name, false}
static bool loadAPI(void *(*getFunc)(const char *))
{
if(!getFunc)
return false;
struct ApiFunc { void **ptr; const char *name; bool required; };
const ApiFunc funcs[] {
REQUIRED_API(ShowConsoleMsg),
};
for(const ApiFunc &func : funcs) {
*func.ptr = getFunc(func.name);
if(func.required && !*func.ptr) {
fprintf(stderr, "[reaper_barebone] Unable to import the following API function: %s\n", func.name);
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment