Merge pull request #13060 from karroffel/gdnative-version-error
[GDNative] (version-) error reporting + small API change
This commit is contained in:
commit
90e37d58d5
7 changed files with 49 additions and 27 deletions
|
@ -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'] + ','
|
||||
]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -89,11 +89,6 @@ wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, cons
|
|||
return self->operator[](p_idx);
|
||||
}
|
||||
|
||||
const char GDAPI *godot_string_c_str(const godot_string *p_self) {
|
||||
const String *self = (const String *)p_self;
|
||||
return self->utf8().get_data();
|
||||
}
|
||||
|
||||
const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) {
|
||||
const String *self = (const String *)p_self;
|
||||
return self->c_str();
|
||||
|
|
|
@ -4361,13 +4361,6 @@
|
|||
["const godot_int", "p_idx"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "godot_string_c_str",
|
||||
"return_type": "const char *",
|
||||
"arguments": [
|
||||
["const godot_string *", "p_self"]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "godot_string_unicode_str",
|
||||
"return_type": "const wchar_t *",
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -68,7 +68,6 @@ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *
|
|||
|
||||
wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx);
|
||||
wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx);
|
||||
const char GDAPI *godot_string_c_str(const godot_string *p_self);
|
||||
const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self);
|
||||
|
||||
godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b);
|
||||
|
|
Loading…
Reference in a new issue