MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _new

Method _new

modules/mono/csharp_script.cpp:2418–2452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2416}
2417
2418Variant CSharpScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
2419 if (!valid) {
2420 r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
2421 return Variant();
2422 }
2423
2424 r_error.error = Callable::CallError::CALL_OK;
2425
2426 StringName native_name;
2427 GDMonoCache::managed_callbacks.ScriptManagerBridge_GetScriptNativeName(this, &native_name);
2428
2429 ERR_FAIL_COND_V(native_name == StringName(), Variant());
2430
2431 Object *owner = ClassDB::instantiate(native_name);
2432
2433 Ref<RefCounted> ref;
2434 RefCounted *r = Object::cast_to<RefCounted>(owner);
2435 if (r) {
2436 ref = Ref<RefCounted>(r);
2437 }
2438
2439 CSharpInstance *instance = _create_instance(p_args, p_argcount, owner, r != nullptr, r_error);
2440 if (!instance) {
2441 if (ref.is_null()) {
2442 memdelete(owner); // no owner, sorry
2443 }
2444 return Variant();
2445 }
2446
2447 if (ref.is_valid()) {
2448 return ref;
2449 } else {
2450 return owner;
2451 }
2452}
2453
2454ScriptInstance *CSharpScript::instance_create(Object *p_this) {
2455#ifdef DEBUG_ENABLED

Callers

nothing calls this directly

Calls 5

memdeleteFunction · 0.85
VariantClass · 0.50
StringNameClass · 0.50
is_nullMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected