summaryrefslogtreecommitdiff
path: root/modules/gdnative/nativescript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/nativescript')
-rw-r--r--modules/gdnative/nativescript/api_generator.cpp34
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp29
-rw-r--r--modules/gdnative/nativescript/nativescript.h1
3 files changed, 62 insertions, 2 deletions
diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp
index 4577c7327a..e0cf990f83 100644
--- a/modules/gdnative/nativescript/api_generator.cpp
+++ b/modules/gdnative/nativescript/api_generator.cpp
@@ -139,6 +139,34 @@ static String get_type_name(const PropertyInfo &info) {
}
/*
+ * Some comparison helper functions we need
+ */
+
+struct MethodInfoComparator {
+ StringName::AlphCompare compare;
+ bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const {
+
+ return compare(p_a.name, p_b.name);
+ }
+};
+
+struct PropertyInfoComparator {
+ StringName::AlphCompare compare;
+ bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const {
+
+ return compare(p_a.name, p_b.name);
+ }
+};
+
+struct ConstantAPIComparator {
+ NoCaseComparator compare;
+ bool operator()(const ConstantAPI &p_a, const ConstantAPI &p_b) const {
+
+ return compare(p_a.constant_name, p_b.constant_name);
+ }
+};
+
+/*
* Reads the entire Godot API to a list
*/
List<ClassAPI> generate_c_api_classes() {
@@ -147,6 +175,7 @@ List<ClassAPI> generate_c_api_classes() {
List<StringName> classes;
ClassDB::get_class_list(&classes);
+ classes.sort_custom<StringName::AlphCompare>();
// Register global constants as a fake GlobalConstants singleton class
{
@@ -162,6 +191,7 @@ List<ClassAPI> generate_c_api_classes() {
constant_api.constant_value = GlobalConstants::get_global_constant_value(i);
global_constants_api.constants.push_back(constant_api);
}
+ global_constants_api.constants.sort_custom<ConstantAPIComparator>();
api.push_back(global_constants_api);
}
@@ -193,6 +223,7 @@ List<ClassAPI> generate_c_api_classes() {
{
List<String> constant;
ClassDB::get_integer_constant_list(class_name, &constant, true);
+ constant.sort_custom<NoCaseComparator>();
for (List<String>::Element *c = constant.front(); c != NULL; c = c->next()) {
ConstantAPI constant_api;
constant_api.constant_name = c->get();
@@ -206,6 +237,7 @@ List<ClassAPI> generate_c_api_classes() {
{
List<MethodInfo> signals_;
ClassDB::get_signal_list(class_name, &signals_, true);
+ signals_.sort_custom<MethodInfoComparator>();
for (int i = 0; i < signals_.size(); i++) {
SignalAPI signal;
@@ -245,6 +277,7 @@ List<ClassAPI> generate_c_api_classes() {
{
List<PropertyInfo> properties;
ClassDB::get_property_list(class_name, &properties, true);
+ properties.sort_custom<PropertyInfoComparator>();
for (List<PropertyInfo>::Element *p = properties.front(); p != NULL; p = p->next()) {
PropertyAPI property_api;
@@ -272,6 +305,7 @@ List<ClassAPI> generate_c_api_classes() {
{
List<MethodInfo> methods;
ClassDB::get_method_list(class_name, &methods, true);
+ methods.sort_custom<MethodInfoComparator>();
for (List<MethodInfo>::Element *m = methods.front(); m != NULL; m = m->next()) {
MethodAPI method_api;
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 5cf144d4fe..f30c9da4c1 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -32,6 +32,7 @@
#include "gdnative/gdnative.h"
+#include "core/core_string_names.h"
#include "core/global_constants.h"
#include "core/io/file_access_encrypted.h"
#include "core/os/file_access.h"
@@ -771,6 +772,27 @@ void NativeScriptInstance::notification(int p_notification) {
call_multilevel("_notification", args, 1);
}
+String NativeScriptInstance::to_string(bool *r_valid) {
+ if (has_method(CoreStringNames::get_singleton()->_to_string)) {
+ Variant::CallError ce;
+ Variant ret = call(CoreStringNames::get_singleton()->_to_string, NULL, 0, ce);
+ if (ce.error == Variant::CallError::CALL_OK) {
+ if (ret.get_type() != Variant::STRING) {
+ if (r_valid)
+ *r_valid = false;
+ ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
+ ERR_FAIL_V(String());
+ }
+ if (r_valid)
+ *r_valid = true;
+ return ret.operator String();
+ }
+ }
+ if (r_valid)
+ *r_valid = false;
+ return String();
+}
+
void NativeScriptInstance::refcount_incremented() {
Variant::CallError err;
call("_refcount_incremented", NULL, 0, err);
@@ -1309,7 +1331,7 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) {
for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) {
Vector<void *> &binding_data = *E->get();
- if (binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data)
+ if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data)
binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]);
}
@@ -1345,7 +1367,7 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
if (!(*binding_data)[p_idx]) {
- const void *global_type_tag = global_type_tags[p_idx].get(p_object->get_class_name());
+ const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name());
// no binding data yet, soooooo alloc new one \o/
(*binding_data).write[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
@@ -1454,6 +1476,9 @@ const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_cl
const HashMap<StringName, const void *> &tags = global_type_tags[p_idx];
+ if (!tags.has(p_class_name))
+ return NULL;
+
const void *tag = tags.get(p_class_name);
return tag;
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index a6865c6243..be1c499714 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -208,6 +208,7 @@ public:
virtual bool has_method(const StringName &p_method) const;
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
virtual void notification(int p_notification);
+ String to_string(bool *r_valid);
virtual Ref<Script> get_script() const;
virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;