2016-06-26 14:02:15 +00:00
|
|
|
/*************************************************************************/
|
2017-07-13 23:44:14 +00:00
|
|
|
/* register_types.cpp */
|
2016-06-26 14:02:15 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-26 14:02:15 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2017-07-13 23:44:14 +00:00
|
|
|
#include "register_types.h"
|
2016-06-26 14:02:15 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
#include "io/resource_loader.h"
|
|
|
|
#include "io/resource_saver.h"
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
#include "nativescript.h"
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
#include "core/os/os.h"
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
NativeScriptLanguage *native_script_language;
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
typedef void (*native_script_init_fn)(void *);
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
|
|
|
|
if (p_handle == NULL) {
|
|
|
|
ERR_PRINT("No valid library handle, can't call nativescript init procedure");
|
|
|
|
return;
|
|
|
|
}
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
void *library_proc;
|
|
|
|
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
|
|
|
p_handle,
|
|
|
|
*(String *)p_proc_name,
|
|
|
|
library_proc);
|
|
|
|
if (err != OK) {
|
|
|
|
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
|
|
|
|
return;
|
|
|
|
}
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
native_script_init_fn fn = (native_script_init_fn)library_proc;
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
fn(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
|
|
|
|
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
void register_nativescript_types() {
|
|
|
|
native_script_language = memnew(NativeScriptLanguage);
|
2017-04-17 19:42:11 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
ClassDB::register_class<NativeScript>();
|
2017-04-17 19:42:11 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
ScriptServer::register_language(native_script_language);
|
2017-04-17 19:42:11 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb);
|
2017-04-17 19:42:11 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
|
|
|
|
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
resource_loader_gdns = memnew(ResourceFormatLoaderNativeScript);
|
|
|
|
ResourceLoader::add_resource_format_loader(resource_loader_gdns);
|
2016-06-26 14:02:15 +00:00
|
|
|
}
|
2017-04-09 19:07:53 +00:00
|
|
|
|
2017-07-13 23:44:14 +00:00
|
|
|
void unregister_nativescript_types() {
|
|
|
|
|
|
|
|
memdelete(resource_loader_gdns);
|
|
|
|
|
|
|
|
memdelete(resource_saver_gdns);
|
|
|
|
|
|
|
|
if (native_script_language) {
|
|
|
|
ScriptServer::unregister_language(native_script_language);
|
|
|
|
memdelete(native_script_language);
|
|
|
|
}
|
|
|
|
}
|