MCPcopy Create free account
hub / github.com/borndotcom/react-native-godot / call

Method call

common/NativeGodotModule.cpp:570–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568};
569
570void JavascriptCallable::call(const godot::Variant **p_arguments, int p_argcount, godot::Variant &r_return_value, GDExtensionCallError &r_call_error) const {
571 std::shared_ptr<RNWorklet::JsiWorkletContext> wc = _workletContext.lock();
572 if (!wc) {
573 // Func ref no longer valid
574 r_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD;
575 return;
576 }
577
578 auto caller = [p_argcount, p_arguments, &r_return_value, &r_call_error](const JavascriptCallable *c, jsi::Runtime &rt) {
579 auto wc = c->_workletContext.lock();
580 if (!wc) {
581 // WorkletContext no longer valid
582 LOGE("JavascriptCallable::call caller workletContext no longer valid");
583 r_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD;
584 return false;
585 }
586 const jsi::Value &val = c->_funcValue;
587 if (!val.isObject()) {
588 // Func ref no longer valid
589 r_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD;
590 return false;
591 }
592 jsi::Object obj = val.asObject(rt);
593 if (!obj.isFunction(rt)) {
594 // Func ref is not a function
595 r_call_error.error = GDEXTENSION_CALL_ERROR_INVALID_METHOD;
596 return false;
597 }
598 jsi::Function func = obj.asFunction(rt);
599
600 std::vector<jsi::Value> args;
601 args.reserve(p_argcount);
602 for (int i = 0; i < p_argcount; ++i) {
603 args.push_back(GodotHostObject::godotVariantToJsiValue(wc, rt, *p_arguments[i]));
604 }
605 const jsi::Value *argptr = args.data();
606 jsi::Value ret = func.call(rt, argptr, (size_t)p_argcount);
607 r_return_value = GodotHostObject::jsiValueToGodotVariant(wc, rt, ret);
608 r_call_error.error = GDEXTENSION_CALL_OK;
609 return true;
610 };
611 runInContext(this, caller);
612}
613
614jsi::Value createNativeGodotModule(jsi::Runtime &rt, const std::shared_ptr<facebook::react::CallInvoker> &callInvoker) {
615 // Perform initialization

Callers 2

escapeRegExpFunction · 0.45
createNativeGodotModuleFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected