Just for future documentation and forum searches, this here code works in the other direction, that is calling into the Javascript from C++ from an inline function handed to C++, I image it would work for inline functions added to the Globals object as well.
_global->setMethod({ "set_callback" }, [&](const var::NativeFunctionArgs& args) -> var {
auto *obj = args.arguments->getDynamicObject();
if (obj) {
if (auto p = _ref.getProcessor()) {
juce::Result* res;
var fVar(obj);
var args[2] = { 42, 13 };
LockHelpers::SafeLock sl(getMainController(), LockHelpers::ScriptLock);
p->getScriptEngine()->maximumExecutionTime = RelativeTime(3.0);
p->getScriptEngine()->executeInlineFunction(fVar, args, res);
}
}
return { 0 };
});
Obviously this is not safe, and if you don't use an inline function, it will crash your C++ code.
This is rougly the code from
void ProcessorWithScriptingContent::customControlCallbackIdle(ScriptingApi::Content::ScriptComponent *component, const var& controllerValue, Result& r)