| 380 | } |
| 381 | |
| 382 | jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name) override { |
| 383 | godot::StringName propName(name.utf8(rt).c_str()); |
| 384 | if (_value.get_type() == godot::Variant::Type::NIL) { |
| 385 | return jsi::Value(nullptr); |
| 386 | } |
| 387 | if (_value.has_method(propName)) { |
| 388 | std::shared_ptr<RNWorklet::JsiWorkletContext> wc = _workletContext; |
| 389 | return jsi::Function::createFromHostFunction(rt, name, 0, [propName, wc](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) { |
| 390 | // LOGI("Calling: %s", propName.to_utf8_buffer().ptr()); |
| 391 | if (!thisVal.isObject()) { |
| 392 | throw jsi::JSINativeException("Calling Godot Method on a value that is not an object"); |
| 393 | } |
| 394 | jsi::Object obj = thisVal.asObject(rt); |
| 395 | |
| 396 | if (!obj.isHostObject(rt)) { |
| 397 | throw jsi::JSINativeException("Calling Godot Method on a value that is not a HostObject"); |
| 398 | } |
| 399 | |
| 400 | std::shared_ptr<GodotHostObject> ho = obj.getHostObject<GodotHostObject>(rt); |
| 401 | std::vector<godot::Variant> godotArgs; |
| 402 | godotArgs.reserve(count); |
| 403 | for (int i = 0; i < count; ++i) { |
| 404 | godotArgs.push_back(jsiValueToGodotVariant(wc, rt, args[i])); |
| 405 | } |
| 406 | |
| 407 | std::vector<const godot::Variant *> variantArgs = createVariantArgArray(godotArgs); |
| 408 | godot::Variant r_ret; |
| 409 | GDExtensionCallError r_error; |
| 410 | ho->_value.callp(propName, variantArgs.data(), count, r_ret, r_error); |
| 411 | if (r_error.error != GDEXTENSION_CALL_OK) { |
| 412 | std::string mName = (const char *)propName.to_utf8_buffer().ptr(); |
| 413 | throw jsi::JSINativeException(create_method_call_error_string(mName, r_error)); |
| 414 | } |
| 415 | return godotVariantToJsiValue(wc, rt, r_ret); |
| 416 | }); |
| 417 | } |
| 418 | { |
| 419 | bool r_valid = false; |
| 420 | godot::Variant v = _value.get_named(propName, r_valid); |
| 421 | if (r_valid) { |
| 422 | return godotVariantToJsiValue(_workletContext, rt, v); |
| 423 | } |
| 424 | } |
| 425 | throw jsi::JSINativeException(std::string("Unable to resolve name as property or method: ") + name.utf8(rt)); |
| 426 | } |
| 427 | |
| 428 | void set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) override { |
| 429 | godot::StringName propName(name.utf8(rt).c_str()); |
nothing calls this directly
no test coverage detected