summaryrefslogtreecommitdiff
path: root/modules/gdnative
diff options
context:
space:
mode:
authorKarroffel <therzog@mail.de>2017-11-19 23:41:22 +0100
committerKarroffel <therzog@mail.de>2017-11-20 11:09:55 +0100
commit0865365e21b9d5b33f12e48fb6f5f50e19f48e7d (patch)
treee5f61c8b48a0c9afbf9de2126d2ae7a0e3798a14 /modules/gdnative
parentf5e85c61039f8ff17805172c7a417747070bbc98 (diff)
[GDNative] loading error and version error procs
Diffstat (limited to 'modules/gdnative')
-rw-r--r--modules/gdnative/SCsub13
-rw-r--r--modules/gdnative/gdnative.cpp5
-rw-r--r--modules/gdnative/gdnative/gdnative.cpp28
-rw-r--r--modules/gdnative/include/gdnative/gdnative.h17
4 files changed, 49 insertions, 14 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub
index 66b8d5cbdd..485bf4b9df 100644
--- a/modules/gdnative/SCsub
+++ b/modules/gdnative/SCsub
@@ -49,19 +49,6 @@ def _build_gdnative_api_struct_header(api):
'extern "C" {',
'#endif',
'',
- 'typedef struct godot_gdnative_api_version {',
- '\tunsigned int major;',
- '\tunsigned int minor;',
- '} godot_gdnative_api_version;',
- '',
- 'typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;',
- '',
- 'struct godot_gdnative_api_struct {',
- '\tunsigned int type;',
- '\tgodot_gdnative_api_version version;',
- '\tconst godot_gdnative_api_struct *next;',
- '};',
- '',
'enum GDNATIVE_API_TYPES {',
'\tGDNATIVE_' + api['core']['type'] + ','
]
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 44d6dffc85..7949ca182f 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -109,6 +109,9 @@ Ref<GDNativeLibrary> GDNative::get_library() {
return library;
}
+extern "C" void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have);
+extern "C" void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what);
+
bool GDNative::initialize() {
if (library.is_null()) {
ERR_PRINT("No library set, can't initialize GDNative object");
@@ -168,6 +171,8 @@ bool GDNative::initialize() {
options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE);
options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR);
options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE);
+ options.report_version_mismatch = &_gdnative_report_version_mismatch;
+ options.report_loading_error = &_gdnative_report_loading_error;
options.gd_native_library = (godot_object *)(get_library().ptr());
options.active_library_path = (godot_string *)&path;
diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp
index 6dfa7ec20b..34b73558d5 100644
--- a/modules/gdnative/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative/gdnative.cpp
@@ -36,6 +36,8 @@
#include "os/os.h"
#include "variant.h"
+#include "modules/gdnative/gdnative.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -137,6 +139,32 @@ void GDAPI godot_print(const godot_string *p_message) {
print_line(*(String *)p_message);
}
+void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) {
+ String message = "Error loading GDNative file ";
+ GDNativeLibrary *library = (GDNativeLibrary *)p_library;
+
+ message += library->get_current_library_path() + ": Extension \"" + p_ext + "\" can't be loaded.\n";
+
+ Dictionary versions;
+ versions["have_major"] = p_have.major;
+ versions["have_minor"] = p_have.minor;
+ versions["want_major"] = p_want.major;
+ versions["want_minor"] = p_want.minor;
+
+ message += String("Got version {have_major}.{have_minor} but needs {want_major}.{want_minor}!").format(versions);
+
+ _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
+}
+
+void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what) {
+ String message = "Error loading GDNative file ";
+ GDNativeLibrary *library = (GDNativeLibrary *)p_library;
+
+ message += library->get_current_library_path() + ": " + p_what;
+
+ _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h
index 38a42ab658..e8d509508e 100644
--- a/modules/gdnative/include/gdnative/gdnative.h
+++ b/modules/gdnative/include/gdnative/gdnative.h
@@ -229,13 +229,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj
godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error);
////// Script API
-struct godot_gdnative_api_struct; // Forward declaration
+typedef struct godot_gdnative_api_version {
+ unsigned int major;
+ unsigned int minor;
+} godot_gdnative_api_version;
+
+typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;
+
+struct godot_gdnative_api_struct {
+ unsigned int type;
+ godot_gdnative_api_version version;
+ const godot_gdnative_api_struct *next;
+};
+
+#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor)
typedef struct {
godot_bool in_editor;
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
+ void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have);
+ void (*report_loading_error)(const godot_object *p_library, const char *p_what);
godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized
const struct godot_gdnative_core_api_struct *api_struct;
const godot_string *active_library_path;