diff options
| author | Karroffel | 2017-07-14 01:44:14 +0200 |
|---|---|---|
| committer | Karroffel | 2017-07-24 04:23:37 +0200 |
| commit | 534d62d2f4ea1ff4be11b50bc79684b5780e4615 (patch) | |
| tree | 0d299c22cbffc2a353c126372a44f067914b71d0 /modules/gdnative/register_types.cpp | |
| parent | 85aa0adeef6ab89e98105fdaa49f441e5763d970 (diff) | |
| download | godot-534d62d2f4ea1ff4be11b50bc79684b5780e4615.tar.gz godot-534d62d2f4ea1ff4be11b50bc79684b5780e4615.tar.zst godot-534d62d2f4ea1ff4be11b50bc79684b5780e4615.zip | |
[GDNative] new GDNative API
This adds GDNative as a separate class type.
It can be used to interface with native libraries by
using "native calls", which can be registered by modules
(and in future other GDNative libraries?).
It also reworks the currently called "GDNativeScript" into a
"NativeScript" that just makes use of the new GDNative instead
of it being the component that implements that functionality.
Diffstat (limited to 'modules/gdnative/register_types.cpp')
| -rw-r--r-- | modules/gdnative/register_types.cpp | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 8789c9a26..20ac1ecc0 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -33,34 +33,46 @@ #include "io/resource_loader.h" #include "io/resource_saver.h" -GDNativeScriptLanguage *script_language_gdn = NULL; -ResourceFormatLoaderGDNativeScript *resource_loader_gdn = NULL; -ResourceFormatSaverGDNativeScript *resource_saver_gdn = NULL; -//ResourceFormatLoaderDLLibrary *resource_loader_dllib=NULL; +#include "core/os/os.h" -void register_gdnative_types() { +godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, godot_array *p_args) { + if (handle == NULL) { + ERR_PRINT("No valid library handle, can't call standard varcall procedure"); + godot_variant ret; + godot_variant_new_nil(&ret); + return ret; + } - ClassDB::register_class<GDNativeLibrary>(); - ClassDB::register_class<GDNativeScript>(); + void *library_proc; + Error err = OS::get_singleton()->get_dynamic_library_symbol_handle( + handle, + *(String *)p_procedure, + library_proc); + if (err != OK) { + ERR_PRINT((String("GDNative procedure \"" + *(String *)p_procedure) + "\" does not exists and can't be called").utf8().get_data()); + godot_variant ret; + godot_variant_new_nil(&ret); + return ret; + } + + godot_gdnative_procedure_fn proc; + proc = (godot_gdnative_procedure_fn)library_proc; - script_language_gdn = memnew(GDNativeScriptLanguage); - ScriptServer::register_language(script_language_gdn); - resource_loader_gdn = memnew(ResourceFormatLoaderGDNativeScript); - ResourceLoader::add_resource_format_loader(resource_loader_gdn); - resource_saver_gdn = memnew(ResourceFormatSaverGDNativeScript); - ResourceSaver::add_resource_format_saver(resource_saver_gdn); + return proc(NULL, p_args); } -void unregister_gdnative_types() { +GDNativeCallRegistry *GDNativeCallRegistry::singleton; - ScriptServer::unregister_language(script_language_gdn); +void register_gdnative_types() { - if (script_language_gdn) - memdelete(script_language_gdn); + ClassDB::register_class<GDNativeLibrary>(); + ClassDB::register_class<GDNative>(); + + GDNativeCallRegistry::singleton = memnew(GDNativeCallRegistry); - if (resource_loader_gdn) - memdelete(resource_loader_gdn); + GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); +} - if (resource_saver_gdn) - memdelete(resource_saver_gdn); +void unregister_gdnative_types() { + memdelete(GDNativeCallRegistry::singleton); } |
