diff options
Diffstat (limited to 'modules/gdnative/gdnative.cpp')
-rw-r--r-- | modules/gdnative/gdnative.cpp | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 373b98dc8b..3fc04a5498 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -199,10 +199,7 @@ void GDNative::_bind_methods() { ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize); ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate); - // TODO(karroffel): get_native_(raw_)call_types binding? - - // TODO(karroffel): make this a varargs function? - ClassDB::bind_method(D_METHOD("call_native", "procedure_name", "arguments"), &GDNative::call_native); + ClassDB::bind_method(D_METHOD("call_native", "calling_type", "procedure_name", "arguments"), &GDNative::call_native); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); } @@ -239,10 +236,7 @@ bool GDNative::initialize() { } void *library_init; - err = OS::get_singleton()->get_dynamic_library_symbol_handle( - native_handle, - init_symbol, - library_init); + err = get_symbol(init_symbol, library_init); if (err || !library_init) { OS::get_singleton()->close_dynamic_library(native_handle); @@ -277,11 +271,8 @@ bool GDNative::terminate() { } void *library_terminate; - Error error = OS::get_singleton()->get_dynamic_library_symbol_handle( - native_handle, - terminate_symbol, - library_terminate); - if (error) { + Error error = get_symbol(terminate_symbol, library_terminate); + if (error || !library_terminate) { OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; return true; @@ -313,10 +304,6 @@ void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, nat native_calls.insert(p_call_type, p_callback); } -void GDNativeCallRegistry::register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback) { - native_raw_calls.insert(p_raw_call_type, p_callback); -} - Vector<StringName> GDNativeCallRegistry::get_native_call_types() { Vector<StringName> call_types; call_types.resize(native_calls.size()); @@ -329,18 +316,6 @@ Vector<StringName> GDNativeCallRegistry::get_native_call_types() { return call_types; } -Vector<StringName> GDNativeCallRegistry::get_native_raw_call_types() { - Vector<StringName> call_types; - call_types.resize(native_raw_calls.size()); - - size_t idx = 0; - for (Map<StringName, native_raw_call_cb>::Element *E = native_raw_calls.front(); E; E = E->next(), idx++) { - call_types[idx] = E->key(); - } - - return call_types; -} - Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) { Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type); @@ -349,20 +324,34 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced return Variant(); } - String procedure_name = p_procedure_name; - godot_variant result = E->get()(native_handle, (godot_string *)&procedure_name, (godot_array *)&p_arguments); + void *procedure_handle; + + Error err = OS::get_singleton()->get_dynamic_library_symbol_handle( + native_handle, + p_procedure_name, + procedure_handle); + + if (err != OK || procedure_handle == NULL) { + return Variant(); + } + + godot_variant result = E->get()(procedure_handle, (godot_array *)&p_arguments); return *(Variant *)&result; } -void GDNative::call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return) { +Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { - Map<StringName, native_raw_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_raw_calls.find(p_raw_call_type); - if (!E) { - ERR_PRINT((String("No handler for native raw call type \"" + p_raw_call_type) + "\" found").utf8().get_data()); - return; + if (native_handle == NULL) { + ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); + return ERR_CANT_OPEN; } - String procedure_name = p_procedure_name; - E->get()(native_handle, (godot_string *)&procedure_name, data, num_args, args, r_return); + Error result = OS::get_singleton()->get_dynamic_library_symbol_handle( + native_handle, + p_procedure_name, + r_handle, + true); + + return result; } |