Yes it's relatively easy (but there is not much documentation). I think it would be a good idea to expose these functions in SWS (I'm interested in kbd_getTextFromCmd, I'll look into doing that later).
Minimal example for adding a custom API function and exposing it to ReaScript:
Code:
static const char *definition = "double\0char*,int\0str,flag\0help text for myfunction";
static double cImpl(char *str, int flag)
{
return 0;
}
static void *reascriptImpl(void **argv, int argc)
{
// argument count check is already done by reaper
return (void *)(intptr_t)cImpl((char *)argv[0], (int)(intptr_t)argv[1]);
}
void registerAPI()
{
// call when initializing the extension
plugin_register("API_functionName", (void *)&cImpl);
plugin_register("APIvararg_functionName", (void *)&reascriptImpl);
plugin_register("APIdef_functionName", (void *)definition);
}
void removeAPI()
{
// call when unloading the extension
plugin_register("-API_functionName", (void *)&cImpl);
plugin_register("-APIvararg_functionName", (void *)&reascriptImpl);
plugin_register("-APIdef_functionName", (void *)definition);
}
(This gets repetitive when adding many functions so I made helper functions and macros to clean this up and have the compiler generate the ugly reascript implementations automatically:
https://github.com/cfillion/reapack/...api_helper.hpp. SWS uses a PHP script to generate them.)