summaryrefslogtreecommitdiffstats
path: root/core/object/object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/object.cpp')
-rw-r--r--core/object/object.cpp83
1 files changed, 59 insertions, 24 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp
index cc33d0ab8a..b34182cdaa 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -29,6 +29,7 @@
/**************************************************************************/
#include "object.h"
+#include "object.compat.inc"
#include "core/core_string_names.h"
#include "core/extension/gdextension_manager.h"
@@ -492,14 +493,22 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
ClassDB::get_property_list(current_extension->class_name, p_list, true, this);
if (current_extension->get_property_list) {
- uint32_t pcount;
- const GDExtensionPropertyInfo *pinfo = current_extension->get_property_list(_extension_instance, &pcount);
- for (uint32_t i = 0; i < pcount; i++) {
- p_list->push_back(PropertyInfo(pinfo[i]));
- }
- if (current_extension->free_property_list) {
- current_extension->free_property_list(_extension_instance, pinfo);
+#ifdef TOOLS_ENABLED
+ // If this is a placeholder, we can't call into the GDExtension on the parent class,
+ // because we don't have a real instance of the class to give it.
+ if (likely(!_extension->is_placeholder)) {
+#endif
+ uint32_t pcount;
+ const GDExtensionPropertyInfo *pinfo = current_extension->get_property_list(_extension_instance, &pcount);
+ for (uint32_t i = 0; i < pcount; i++) {
+ p_list->push_back(PropertyInfo(pinfo[i]));
+ }
+ if (current_extension->free_property_list) {
+ current_extension->free_property_list(_extension_instance, pinfo);
+ }
+#ifdef TOOLS_ENABLED
}
+#endif
}
current_extension = current_extension->parent;
@@ -1464,6 +1473,7 @@ void Object::initialize_class() {
}
ClassDB::_add_class<Object>();
_bind_methods();
+ _bind_compatibility_methods();
initialized = true;
}
@@ -1473,10 +1483,15 @@ String Object::tr(const StringName &p_message, const StringName &p_context) cons
}
if (Engine::get_singleton()->is_editor_hint()) {
+ String tr_msg = TranslationServer::get_singleton()->extractable_translate(p_message, p_context);
+ if (!tr_msg.is_empty()) {
+ return tr_msg;
+ }
+
return TranslationServer::get_singleton()->tool_translate(p_message, p_context);
- } else {
- return TranslationServer::get_singleton()->translate(p_message, p_context);
}
+
+ return TranslationServer::get_singleton()->translate(p_message, p_context);
}
String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
@@ -1489,10 +1504,15 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu
}
if (Engine::get_singleton()->is_editor_hint()) {
+ String tr_msg = TranslationServer::get_singleton()->extractable_translate_plural(p_message, p_message_plural, p_n, p_context);
+ if (!tr_msg.is_empty()) {
+ return tr_msg;
+ }
+
return TranslationServer::get_singleton()->tool_translate_plural(p_message, p_message_plural, p_n, p_context);
- } else {
- return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
}
+
+ return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
}
void Object::_clear_internal_resource_paths(const Variant &p_var) {
@@ -1639,8 +1659,8 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation);
ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages);
- ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion);
ClassDB::bind_method(D_METHOD("cancel_free"), &Object::cancel_free);
@@ -1792,6 +1812,16 @@ uint32_t Object::get_edited_version() const {
#endif
StringName Object::get_class_name_for_extension(const GDExtension *p_library) const {
+#ifdef TOOLS_ENABLED
+ // If this is the library this extension comes from and it's a placeholder, we
+ // have to return the closest native parent's class name, so that it doesn't try to
+ // use this like the real object.
+ if (unlikely(_extension && _extension->library == p_library && _extension->is_placeholder)) {
+ const StringName *class_name = _get_class_namev();
+ return *class_name;
+ }
+#endif
+
// Only return the class name per the extension if it matches the given p_library.
if (_extension && _extension->library == p_library) {
return _extension->class_name;
@@ -1919,13 +1949,15 @@ void Object::clear_internal_extension() {
// Clear the instance bindings.
_instance_binding_mutex.lock();
- if (_instance_bindings[0].free_callback) {
- _instance_bindings[0].free_callback(_instance_bindings[0].token, this, _instance_bindings[0].binding);
+ if (_instance_bindings) {
+ if (_instance_bindings[0].free_callback) {
+ _instance_bindings[0].free_callback(_instance_bindings[0].token, this, _instance_bindings[0].binding);
+ }
+ _instance_bindings[0].binding = nullptr;
+ _instance_bindings[0].token = nullptr;
+ _instance_bindings[0].free_callback = nullptr;
+ _instance_bindings[0].reference_callback = nullptr;
}
- _instance_bindings[0].binding = nullptr;
- _instance_bindings[0].token = nullptr;
- _instance_bindings[0].free_callback = nullptr;
- _instance_bindings[0].reference_callback = nullptr;
_instance_binding_mutex.unlock();
// Clear the virtual methods.
@@ -2064,15 +2096,17 @@ void ObjectDB::debug_objects(DebugFunc p_func) {
spin_lock.unlock();
}
+#ifdef TOOLS_ENABLED
void Object::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
+ const String pf = p_function;
if (p_idx == 0) {
- if (p_function == "connect" || p_function == "is_connected" || p_function == "disconnect" || p_function == "emit_signal" || p_function == "has_signal") {
+ if (pf == "connect" || pf == "is_connected" || pf == "disconnect" || pf == "emit_signal" || pf == "has_signal") {
List<MethodInfo> signals;
get_signal_list(&signals);
for (const MethodInfo &E : signals) {
r_options->push_back(E.name.quote());
}
- } else if (p_function == "call" || p_function == "call_deferred" || p_function == "callv" || p_function == "has_method") {
+ } else if (pf == "call" || pf == "call_deferred" || pf == "callv" || pf == "has_method") {
List<MethodInfo> methods;
get_method_list(&methods);
for (const MethodInfo &E : methods) {
@@ -2081,7 +2115,7 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
}
r_options->push_back(E.name.quote());
}
- } else if (p_function == "set" || p_function == "set_deferred" || p_function == "get") {
+ } else if (pf == "set" || pf == "set_deferred" || pf == "get") {
List<PropertyInfo> properties;
get_property_list(&properties);
for (const PropertyInfo &E : properties) {
@@ -2089,13 +2123,13 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
r_options->push_back(E.name.quote());
}
}
- } else if (p_function == "set_meta" || p_function == "get_meta" || p_function == "has_meta" || p_function == "remove_meta") {
+ } else if (pf == "set_meta" || pf == "get_meta" || pf == "has_meta" || pf == "remove_meta") {
for (const KeyValue<StringName, Variant> &K : metadata) {
r_options->push_back(String(K.key).quote());
}
}
} else if (p_idx == 2) {
- if (p_function == "connect") {
+ if (pf == "connect") {
// Ideally, the constants should be inferred by the parameter.
// But a parameter's PropertyInfo does not store the enum they come from, so this will do for now.
List<StringName> constants;
@@ -2106,6 +2140,7 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
}
}
}
+#endif
SpinLock ObjectDB::spin_lock;
uint32_t ObjectDB::slot_count = 0;