[GDNative] loading error and version error procs

This commit is contained in:
Karroffel 2017-11-19 23:41:22 +01:00
parent f5e85c6103
commit 0865365e21
4 changed files with 49 additions and 14 deletions

View File

@ -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'] + ','
]

View File

@ -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;

View File

@ -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

View File

@ -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;